Problem:


Score : 300 points

Problem Statement

We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.

Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.

How many combinations of "on" and "off" states of the switches light all the bulbs?

Constraints

1 \leq N, M \leq 10

1 \leq k_i \leq N

1 \leq s_{ij} \leq N

s_{ia} \neq s_{ib} (a \neq b)

p_i is 0 or 1.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
k_1 s_{11} s_{12} ... s_{1k_1}
:
k_M s_{M1} s_{M2} ... s_{Mk_M}
p_1 p_2 ... p_M

Output

Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.

Sample Input 1

2 2
2 1 2
1 2
0 1

Sample Output 1

1

Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2.

Bulb 2 is lighted when there is an odd number of switches that are "on" among the following: Switch 2.

There are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.

Sample Input 2

2 3
2 1 2
1 1
1 2
0 0 1

Sample Output 2

0

Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2.

Bulb 2 is lighted when there is an even number of switches that are "on" among the following: Switch 1.

Bulb 3 is lighted when there is an odd number of switches that are "on" among the following: Switch 2.

Switch 1 has to be "off" to light Bulb 2 and Switch 2 has to be "on" to light Bulb 3, but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0.

Sample Input 3

5 2
3 1 2 5
2 2 3
1 0

Sample Output 3

8



Sample input:
2 2
2 1 2
1 2
0 1


Sample output:
1

Submission status: Wrong Answer

Solution code:
import itertools
count =0
ans=0
n,m = map(int,input().split())
pattern = list(itertools.permutations(range(2), n))
#pattern.append([0]*m)
#pattern.append([1]*m)

lists =[]
switches = [1]*n
onoff = [0]*m
for i in range(m):
    lists.append(list(map(int,input().split())))
key_value = list(map(int,input().split()))
for l in pattern:
    switches = list(l)
    for j in range(m):
        for k in range(int(lists[j][0])):
            if switches[k] == 1:
                count += 1
        if count %2 == key_value[j]:
            onoff[j] = 1
        else:
            break
    if not 0 in onoff:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
count =0
ans=0
n,m = map(int,input().split())
pattern = list(itertools.permutations(range(2), n))
#pattern.append([0]*m)
#pattern.append([1]*m)

lists =[]
switches = [1]*n
onoff = [0]*m
for i in range(m):
    lists.append(list(map(int,input().split())))
key_value = list(map(int,input().split()))
for l in pattern:
    switches = list(l)
    print(switches)
    for j in range(m):
        for k in range(int(lists[j][0])):
            if switches[k] == 1:
                count += 1
        if count %2 == key_value[j]:
            onoff[j] = 1
        else:
            break
    if not 0 in onoff:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
switches = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    all_on_flag = 1
    for j in range(m):
        switch = switches[j]
        cnt = 0
        for s in switch:
            if ((i >> (s-1)) & 1):
                cnt += 1
        if cnt % 2 != p[j]:
            all_on_flag = 0
            break
    if all_on_flag:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ks = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))
count = 0

for i in range(2**n):
  SUMLIST = []
  SUM = 0
  check = 0
  l = [0]*n
  for j in range(n):
    if ((i >> j)&1):
      l[n-j-1] = 1
  
  for switch in ks:
    for each in switch[1:]:
      SUM += (l[each-1])
    SUMLIST.append(SUM)
   
  for i in range(m):
    if SUMLIST[i]%2 == p[i]:
      check += 1
      
  if check == m:
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
ks = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))
count = 0

for i in range(2**n):
  SUMLIST = []
  SUM = 0
  check = 0
  l = [0]*n
  for j in range(n):
    if ((i >> j)&1):
      l[n-j-1] = 1
  
  for switch in ks:
    for each in range(1,len(switch)):
      SUM += (l[each-1])
    SUMLIST.append(SUM)
   
  for i in range(m):
    if SUMLIST[i]%2 == p[i]:
      check += 1
      
  if check == m:
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
k=[]
cnt=0
flag=True
ans=0
for i in range(m):
  t=list(map(int,input().split()))
  k.append(t)
p=list(map(int,input().split()))

for i in range(2**n):
  flag=True
  cnt=0
  for j in range(m):
    for l in range(len(k[j])-1):
      if (i>>(k[j][l+1]-1))&1:
        cnt+=1
    if cnt%2!=p[j]:
      flag=False
      break
  if flag:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
# スイッチONとOFFで、電球と繋がっている繋がっていないも、0or1なので、ビット演算を使用するのが吉

# スイッチと電球の繋がりをビット列で表す
# スイッチ(行）と電球(列)のマトリクスを作って、繋がっているところに1、繋がっていないところに0
# 行方向に見るとスイッチがどの電球に繋がっているかのビット列ができる
# intで持ってもよいので、100 は　4　

# 電球が点いているか点いていないかをビット列で表す
# スイッチを押すたびに、1つ前のスイッチが繋がっている電球にそのスイッチも繋がっていれば、偶奇が変化してスイッチの点滅が変化する
# スイッチを押すたびにxorをとる
# 電球の点滅とpが一致していればok


n, m = map(int, input().split())

# kはスイッチ、sはスイッチが繋がっている電球を表す
k = []
s = []

for _ in range(m):
    tmp = tuple(map(int, input().split()))
    k.append(tmp[0])
    s.append(set(tmp[1:-1]))
 
p = tuple(map(int, input().split()))
 
# print(k, s, p, sep="\n")

ans = 0

# スイッチの押し方を全部試す
for i in range(2 ** n):
    # 各iでonになっている電球の数
    light_on = 0
 
    # 電球jについて
    for j in range(m):
        switch_on = 0
 
        for k in range(n):
            # onになっているスイッチ（kビット目が立っているか）
            if (i >> k) & 1:
                # 電球jとつながっているものならカウント
                # sはスイッチkが繋がっている電球jのリスト
                # スイッチは1からなので、k+1
                if k + 1 in s[j]:
                    switch_on += 1
 
        # onになっているスイッチの個数がp[j]に等しいなら電球jは点灯している
        if switch_on % 2 == p[j]:
            light_on += 1
 
    # 全ての電球が点灯しているならカウント
    if light_on == m:
        # print(bin(i))
        ans += 1
 
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, M = map(int,input().split())

k = [0]*M
N_ = np.zeros((N,M))

print(N_.shape)

Submission status: Wrong Answer

Solution code:
from itertools import product 
n,m = map(int,input().split())
lamp = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))

ans = 0
for i in product([0,1],repeat=n):
    tmp = 0
    ac = True
    for k,b in enumerate(lamp):
        for a in b[1:]:
            tmp += i[a-1]
        if p[k] != (tmp%2):
            ac = False
            break
    if ac:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product 
n,m = map(int,input().split())
lamp = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))

ans = 0
for i in product([0,1],repeat=n):
    tmp = 0
    ac = True
    for k,b in enumerate(lamp):
        for a in b[1:]:
            tmp += i[a-1]
        if p[k] != tmp%2:
            ac = False
            break
    if ac:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product 
n,m = map(int,input().split())
lamp = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))

ans = 0
for i in product([0,1],repeat=n):
    tmp = 0
    ac = True
    for k,b in enumerate(lamp):
        for a in b[1:]:
            tmp += int(i[a-1])
        tmp %= 2
        if p[k] != tmp:
            ac = False
            break
    if ac:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product 
n,m = map(int,input().split())
lamp = [list(map(int,input().split())) for _ in range(m)]
p = list(map(int,input().split()))

ans = 0
for i in product('01',repeat=n):
    tmp = 0
    ac = True
    for k,b in enumerate(lamp):
        for a in b[1:]:
            tmp += int(i[a-1])
        tmp %= 2
        if p[k] != tmp:
            ac = False
    if ac == True:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N,M = map(int, input().split())
    s = [[int(x) for x in input().split()] for _ in range(M)]
    p = [int(x) for x in input().split()]
    count=0
    for i in range(2**N):
        switch=[0]*N
        sw = bin(i)[2:]
        sw = "0"*(N-len(sw))+sw
        #print(sw)
        #for j in range(N):
            #switch[j] = int(sw[j])
        All=0   
        for j in range(M):
            Sum=0
            for k in s[j]:
                #if switch[k-1]==1:
                if int(sw[k-1])==1:
                    Sum+=1
            if Sum%2 == p[j]:
                All+=1
        if All==M:
            count+=1
    print(count)

main()

Submission status: Wrong Answer

Solution code:
def main():
    N,M = map(int, input().split())
    s = [[int(x) for x in input().split()] for _ in range(M)]
    p = [int(x) for x in input().split()]
    count=0
    for i in range(2**N):
        switch=[0]*N
        sw = bin(i)[2:]
        sw=sw[:-1]
        sw = "0"*(N-len(sw))+sw
        #for j in range(N):
            #switch[j] = int(sw[j])
        All=0   
        for j in range(M):
            Sum=0
            for k in s[j]:
                #if switch[k-1]==1:
                if int(sw[k-1])==1:
                    Sum+=1
            if Sum%2 == p[j]:
                All+=1
        if All==M:
            count+=1
    print(count)

main()

Submission status: Wrong Answer

Solution code:
n, m=map(int, input().split())
lamp=[]
cnt=0
check=0
pat=0 #パターンが何個あるか
for i in range(m):
  lamp.append(list(map(int, input().split())))
rema=list(map(int, input().split()))
for i in range(2 ** n):
  
  bag = []
  for j in range(n):  
    if ((i >> j) & 1):
      bag.append(1)  
    else:
      bag.append(0)
      #ここまででスイッチの状態が確定
  check=0
  for x in range(m): # lamp を１－Mまでチェック
    cnt==0
    for y in range(lamp[x][0]): #Lampのスイッチの条件を１から最後まであらう）
      if bag[lamp[x][y+1]-1]==1:
        cnt+=1
    if cnt%2==rema[x]:
      check+=1
  if check==m:
    pat+=1
print(pat)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
k_s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

s = bin(0)[2:].zfill(n)
ans = 0

for i in range(2 ** n):
    cnt = 0
    for j in range(m):
        on = 0
        for k in range(k_s[j][0]):
            if s[k_s[j][k] - 1] == '1':
                on += 1
            if k == k_s[j][0] - 1:
                if on % 2 == p[j] and on != 0:
                    cnt += 1
    if cnt == m:
        ans += 1
    s = bin(int(s, 2) + 1)[2:].zfill(n)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations_with_replacement
from operator import itemgetter

N, M = map(int, input().split())
lights = list(tuple(map(int, input().split())) for _ in range(M))
cons = list(map(int, input().split()))

ans = 0
for switch in combinations_with_replacement(range(2), r=N):
    reminders = []
    for idx, light in enumerate(lights):
        f = itemgetter(*map(lambda x: x - 1, light[1:]))
        if isinstance(f(switch), int):
            s = f(switch)
        else:
            s = sum(f(switch))
        reminders.append(s % 2)
    if cons == reminders:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = (int(x) for x in input().split())
swi = []
for i in range(m):
  l = [int(x) for x in input().split()]
  t = 0
  for i in range(1,len(l)):
    t += 1 << (l[i]-1)
  swi.append(t)
ppp = [int(x) for x in input().split()]

ans = 0
for i in range(1 << n):
  for s, p in zip(swi,ppp):
    t = i & s
    c = bin(t).count("1") % 2
    if c != p:
      break
  else:
    print(i)
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [0] * n

for i in range(m):
    k, *s = list(map(int, input().split()))
    for j in range(k):
        a[s[j] - 1] |= 1 << i

p = sum(list(map(int, input().split())))

ans = 0
for s in range(1 << n):
    t = 0
    for i in range(n):
        if s >> i & 1:
            t ^= a[i]
    if t == p:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
k = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
count = 0

for i in range(n**2):
    for l in range(m):
        tmp = 0
        for j in range(n):
            if ((i >> j) & 1)and j+1 in k[l]:
                tmp += 1
        if tmp %2 != p[l]:
            break
    else:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
k = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
count = 0

for i in range(n**2):
    for l in range(m):
        tmp = 0
        for j in range(n):
            if ((i >> j) & 1)and j+1 in k[l]:
                tmp += 1
        print('t', l, tmp)
        if tmp %2 != p[l]:
            break
    else:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
count = 0

for i in range(n**2):
    for l in range(m):
        tmp = 0
        for j in range(n):
            if (i >> j) & 1and j+1 in k[l]:
                tmp += 1
    if tmp %2 == p[l]:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
count = 0

for i in range(n**2):
    for l in range(m):
        tmp = 0
        for j in range(n):
            if (i >> j) & 1and j+i in k[l]:
                tmp += 1
    if tmp %2 == p[l]:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
def check(k,p,list):
    count = 0
    res = 0
    # print(list)
    for i in range(len(k)):
        for j in range(k[i][0]):
            if(k[i][j+1] in list):
                count += 1
        if count % 2 == p[i]:
            res += 1
    # print(count)
    return res == len(k)

n,m = map(int,input().split())
sw = []

for i in range(m):
    sw.append(list(map(int,input().split())))
    # print()
    # print(sw[i])
p = list(map(int,input().split()))
res = 0
# print(p)

for i in range(2**n):
    list = []
    for j in range(n):
        if(i >> j) & 1 == 1:
            list.append(j+1)
    if(check(sw,p,list)):
        res += 1
print(res)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#m = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

l = []
for i in range(m):
    l.append(list(map(int, sys.stdin.readline().split())))

p = list(map(int, sys.stdin.readline().split()))

ans = 0
for i in range(2 ** n):
    g = format(i, "010b")
    for j in range(m):
        cnt = 0
        for k in range(1,l[j][0]+1):
            if g[9-l[j][k]] == "1":
                cnt += 1

        if cnt % 2 != p[j]:
            break

        if j == m - 1:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#C
n,m = map(int,input().split())
denkyu = []
for _ in range(m):
    tmp = list(map(int,input().split()))
    denkyu.append(tmp)   
p = list(map(int,input().split()))

#bit全探索？
import itertools
switch = list(itertools.product([0,1],repeat=n))
cnt = 0

for i in switch:
    gokei = 0
    flg = True
    for j in range(m):
        for k in range(1,len(denkyu[j])):
            gokei += i[denkyu[j][k]-1] 
            
        if gokei % 2 != p[j]:
            flg = False
            
    if flg:
        cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
#C
n,m = map(int,input().split())
denkyu = []
for _ in range(m):
    tmp = list(map(int,input().split()))
    denkyu.append(tmp)   
p = list(map(int,input().split()))

#bit全探索？
import itertools
switch = list(itertools.product([0,1],repeat=n))
cnt = 0

for i in switch:
    gokei = 0
    flg = True
    for j in range(m):
        for k in range(1,len(denkyu[j])):
            gokei += i[denkyu[j][k]-1] 
            
        if gokei % 2 != p[j]:
            flg = False
            break
    if flg:
        cnt += 1
        
print(cnt)

Submission status: Wrong Answer

Solution code:
#１行目の『N M』の取得
N,M=map(int,input().split())

#2-(M+1)行目の取得
switch_li=[[] for _ in range(M)] 
#M個の入れ子のリスト、スイッチの個数、スイッチ何がついているか
for i in range(M):
    li=list(map(int,input().split()))
    switch_li[i].extend(li)
    #appendではなくてextendを使ってリストを展開してから結合する

#スイッチの個数は正直データとして要らないので消す
#del li[0] で値消せる
for i in range(M):
    del switch_li[i][0]
#これでついているスイッチだけを格納したM列の入れ子リストができた

#M+2行目のPの取得
P=list(map(int,input().split()))

#スイッチのつき方の全探索する
#スイッチはN個あり、それが着くか付かないかで、場合の数は、2**N通り
switch_bit=[[] for _ in range(2**N)]
for i in range(2**N):
    for j in range(N):
        if (i>>j)&1==1:
            switch_bit[i].append(j+1)
        else:
            continue
#これで全ての組み合わせを抽出できた（スイッチonのものだけが記載される）

#switch_bitそれぞれについて条件を満たすのかどうか判定する
#まずスイッチ3で考えてみる(具体的でまず考えた方がわかりやすい)、その後それを一般化する
#switch_li{2}の要素をfor文で回して、スイッチonのものに含まれている場合は、リストに追加する
#それを最後に2で割って値を比べる
#まずスイッチ３のままコード書いてあとでそれを修正する
#今は何かスイッチ光っているものが入力されているとする（ここではswitch_bit[i]とする）
#実際実行することを考えると、iでスイッチ光るものを固定（switch_bit）し、j=3でスイッチを固定して光るかどうか判定する


#スイッチのつく組みが与えられている時に、電球がつくかどうか判定する関数を作る
def light_or_not(x,i):
    #xは電球番号
    li=[]
    for k in switch_li[x-1]:
        if k in switch_bit[i]:
            li.append(k)
        else:
            continue
    if len(li)==0:
        return False
    elif len(li)%2==P[x-1]:
        return True
    else:
        return False
    
ans=0
for i in range(2**N):
    for j in range(1,M+2):
        if j==M+1:
            ans+=1
        elif light_or_not(j,i):
            continue
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
def AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p):
    # print(SwitchPattern)
    Light=0
    for m in range(M):
        OnSwitch=0
        for l in range(LineVolume[m]):
            a=Destinations[m][l]-1
            if SwitchPattern[a]==1:
                OnSwitch += 1
            else:
                pass
        if OnSwitch%2==p[m]:
            Light+=1
    print (Light)
    if Light==M:
        return True


N,M=map(int,input().split())
K=[]
for _a in range (M):
    arr=list(map(int,input().split()))
    K.append(arr)
LineVolume=[] #m番目の電球がスイッチとつながっている線の数
Destinations=[] #m番目の電球がつながっているスイッチの番号(1スタート)
for _b in range (M):
    LineVolume.append(K[_b][0])
    Destinations.append(K[_b][1:])
p=list(map(int,input().split()))
# print (LineVolume)
# print (Destinations)
# print(p)

LightOnPattern=0

for Pattern in range (2**N):
    SwitchPattern=[]
    for ONOFF in range(N):
        if(Pattern>>ONOFF)&1==1:
            SwitchPattern.append(1)
        else:
            SwitchPattern.append(0)
    print(SwitchPattern)
    if AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p)==True:
        LightOnPattern += 1

print(LightOnPattern)

Submission status: Wrong Answer

Solution code:
def AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p):
    print(SwitchPattern)
    Light=0
    for m in range(M):
        OnSwitch=0
        for l in range(LineVolume[m]):
            a=Destinations[m][l]-1
            if SwitchPattern[a]==0:
                OnSwitch += 1
        if OnSwitch>0 and OnSwitch%2==p[m]:
            Light+=1
    #print (Light)
    if Light==M:
        return True


N,M=map(int,input().split())
K=[]
for _a in range (M):
    arr=list(map(int,input().split()))
    K.append(arr)
LineVolume=[] #m番目の電球がスイッチとつながっている線の数
Destinations=[] #m番目の電球がつながっているスイッチの番号(1スタート)
for _b in range (M):
    LineVolume.append(K[_b][0])
    Destinations.append(K[_b][1:])
p=list(map(int,input().split()))
# print (LineVolume)
# print (Destinations)
# print(p)

LightOnPattern=0

for Pattern in range (N**2):
    SwitchPattern=[]
    for ONOFF in range(N):
        if(Pattern>>ONOFF)&1==1:
            SwitchPattern.append(1)
        else:
            SwitchPattern.append(0)
    # print(SwitchPattern)
    #print(SwitchPattern)
    if AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p)==True:
        LightOnPattern += 1

print(LightOnPattern)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
u = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))

import itertools
sw = list(itertools.product([0,1],repeat=n))

count = 0
temp=0
for i in range(2**n):
    for j in range(m):
        for s in u[j][1:]:
            if sw[i][s-1]==1:
                temp+=1
        if temp%2!=p[j]:
            break
    else:
        count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import itertools
n,m = map(int,input().split())
l = [tuple(map(int, input().split())) for _ in range(m)]
judge = tuple(map(int, input().split()))
count =0
switch = list(itertools.product([0,1], repeat=n))
for i in range (2**n):
    #スイッチ全探索
    for j in range(m):
        #各電球に焦点
        for k in range(l[j][0]):
            #電球のスイッチ条件に焦点
            cnt =0
            cnt += switch[i][k]
        if cnt%2 != judge[j]:
            break
    else:
        if j == m-1:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
n,m = map(int,input().split())
l = [tuple(map(int, input().split())) for _ in range(m)]
judge = tuple(map(int, input().split()))
count =0
switch = list(itertools.product([0,1], repeat=n))
for i in range (n**2):
    #スイッチ全探索
    for j in range(m):
        #各電球に焦点
        for k in range(l[j][0]):
            #電球のスイッチ条件に焦点
            cnt =0
            cnt += switch[i][k]
        if cnt%2 != judge[j]:
            break
        else:
            if j == m-1:
                count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,M = IL()
data = ILL(M)
p = IL()

B = []
for d in data:
  d = d[1:]
  b = 0
  for i in d:
    b += 1<<(i-1)
  B.append(b)
  
ans = 0
for k in range(1<<N):
  flag = 1
  for i in range(M):
    b = B[i]
    if count_bit(b&k) % 2 == p[i]:
      flag *= 0
  if flag:
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int, input().split()))
k = [list(map(int, input().split()))[1:] for i in range(m)]
p = list(map(int, input().split()))

ans=0
for i in range(2**n):
    # 1,2,3...,Nのスイッチの状態
    state=[(i>>j)&1 for j in range(n)]
#    print('state=',state)
    on_cnt=0
    ok=1
    for ii, x in enumerate(k):
#        print('x=',x)
        for y in x:
            if state[y-1]==1:
                on_cnt+=1
        if on_cnt%2!=p[ii]:
            ok=0
            break
    if ok==1:
        ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
l = []
for _ in range(M):
  l.append(list(map(int, input().split())))
p = list(map(int, input().split()))

m = [0] * M # 電球のonoffチェック。on:1 off:0
cnt1 = 0 # 1の個数を数える
cnt2 = 0 # 答え

for i in range(2 ** N):
  for j in range(M):
    for k in range(l[j][0]):
      if (i >> (l[j][k+1] - 1) & 1):
        cnt1 += 1
    if cnt1 % 2 == p[j-1]:
      m[j-1] = 1
    cnt1 = 0
  if m == [1] * M:
    cnt2 += 1
  m = [0] * M
print(cnt2)

Submission status: Wrong Answer

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

n,m = imap()
k,s = [],[]
for i in range(m):
    tmp = iarr()
    k.append(tmp[0])
    s.append([num-1 for num in tmp[1:]])
p = iarr()

ans = 0
for i in range(2**n):
    bin = iarr(n)
    for j in range(n):
        if i>>j&1: bin[j] = 1
    flag = 1
    for ii,ss in enumerate(s):
        cnt = 0
        for num in ss: cnt += bin[num]
        if cnt%2 == ii: continue
        else: flag = 0; break
    if flag: ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = [int(n) for n in input().split()]
K = [list(map(int, input().split())) for i in range(M)]
P = [int(n) for n in input().split()]


case_cnt = 0
for i in range(2**N):
  bulbs = []
  ons = []
  #switchがON/OFFの入力ケース作成
  for j in range(M):
    if (i >> j) & 1:
      ons.append(j)
  
  OK = True
  #入力ケースにより、各電球でSwithchがONとなる数をカウント
  for k in range(M):
    cnt = 0
    for s in K[k][1:]:
      if s-1 in ons:
        cnt += 1
    #bulbsに電球が光ればTrue, 光らなければFalse
    if P[k] == cnt % 2 :
      bulbs.append(True)
    else:
      bulbs.append(False)
  #全電球が光っているのであれば、カウント
  if all(bulbs):
    case_cnt += 1
print(case_cnt)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s=[list(map(int,input().split())) for x in range(m)]
p=list(map(int,input().split()))
ans=0
for b in range(1<<n):
  flg=True
  for i in range(m):
    cnt=0
    for j in range(s[i][0]):
      if (b >> s[i][j+1]-1)&1:
        cnt+=1
    if cnt %2==p[i]:
      flg=False
  if flg:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N,M=map(int,input().split())

    k_list=[]
    swiches=[]
    for i in range(M):
        inp=list(map(int,input().split()))
        k_list.append(inp[0])
        swiches.append(inp[1:])
    P=list(map(int,input().split()))

    res=0
    for SwichStatus in range(pow(2,N)):
        flag=0
        for i in range(M):
            Link=0
            for swich in swiches[i]:
                Link+=1<<(swich-1)
            OnSwich=SwichStatus&Link
            OnCounter=0
            while OnSwich!=0:
                OnCounter+=OnSwich&1
                OnSwich>>=1
            if OnCounter%2!=P[i]:
                flag=1
                break
        if flag!=1:
            res+=1
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,m = list(map(int,input().split()))
ks = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))

ans = 0
for i in range(1,2**n):
    flag = True
    for j in range(m): #電球
        cnt = 0
        for k in range(1,len(ks[j])):
            w = ks[j][k]
            if i >> (w-1) & 1 :
                cnt+=1
        if cnt%2 != p[j]:
            flag = False
    if flag:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
import copy
k = [0 for i in range(m)]
ans = 0
import copy
for i in range(m):
    k[i] = list(map(int,input().split()))
p = list(map(int,input().split()))
for i in range(2**n):
    v = 1
    u = 0
    d = [0 for i in range(n)]
    q = copy.deepcopy(i)
    for j in range(n):
        if q &1:
            d[j] = 1
        q = q >> 1
    for g in range(m):
        for c in range(1,k[g][0]+1):
            u += d[k[g][c]-1]
        if u%2 == p[g]:
            continue
        else:
            v = 0
            break
    if v:
        ans += 1
print(ans)