Skip to content

Instantly share code, notes, and snippets.

@magurofly
Last active June 4, 2021 00:58
Show Gist options
  • Save magurofly/9ff8afbc130cab58920ee68c5757d7d9 to your computer and use it in GitHub Desktop.
Save magurofly/9ff8afbc130cab58920ee68c5757d7d9 to your computer and use it in GitHub Desktop.
典型057
# 提出: https://atcoder.jp/contests/typical90/submissions/23159483
# 入力
N, M = gets.split.map(&:to_i)
A = Array.new(N) { gets; gets.split.map(&:to_i) }
S = gets.split.map(&:to_i)
# 行ベクトルの配列
xs = A.map { |indices|
x = 0
indices.each do |index|
x |= 1 << index - 1
end
x
}
# 基底を求める
bases = []
xs.each do |x|
bases.each do |base|
x = [x, x ^ base].min
end
bases << x if x != 0
end
# 解く
y = S.join.reverse.to_i(2)
bases.each do |base|
y = [y, y ^ base].min
end
if y != 0
puts 0
exit
end
rank = bases.size
puts 2.pow(N - rank, 998244353)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment