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:
n,m = map(int,input().split())
A = []
ans = 0
for _ in range(m):
    A.append(list(map(int,input().split())))
P = list(map(int,input().split()))
for bit in range(1<<n):
    flag = True
    cnt = 0
    for i in range(m):
        k,S = A[i][0],A[i][1:]
        for s in S:
            if ((bit>>(s-1))&1) and flag == True:
                cnt += 1
        if cnt %2==P[i]:
            continue
        else:
            flag = False
    if flag:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
A = []
ans = 0
for _ in range(m):
    A.append(list(map(int,input().split())))
P = list(map(int,input().split()))
for bit in range(1<<n):
    flag = True
    cnt = 0
    for i in range(m):
        k,S = A[i][0],A[i][1:]
        for s in S:
            if bit & (1<<(s-1)) and flag == True:
                cnt += 1
        if cnt %2==P[i]:
            continue
        else:
            flag = False
    if flag:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def mod2(num):
    return num % 2

def solve():
    # 標準入力
    N, M = list(map(int, input().split()))  # N: スイッチの数， M: 電球の数
    k = [0] * M  # 電球iにつながっているスイッチの数
    s = [[0] for _ in range(M)]  # 電球iにつながっているスイッチの番号
    for i in range(M):
        tmp = list(map(int, input().split()))
        k[i] = tmp[0]
        s[i] = tmp[1::]
    p = list(map(int, input().split()))

    # スイッチの状態を総当たり
    count = 0
    for switch_state in range(2**N):
        p_tmp = [0] * M
        iter_num = format(switch_state, '0'+str(N)+'b')
        # 電球ごとに条件をチェック
        for i, s_i in enumerate(s):
            for s_i_j in s_i:
                if (iter_num[s_i_j - 1] == '1'):
                    p_tmp[i-1] += 1
        if(p == list(map(mod2, p_tmp))):
            count += 1
    print(count)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())

l=[]

for i in range(m):
  l2=list(map(int, input().split()))
  l.append(l2)
  
p=list(map(int, input().split()))
ans=0
for i in range(2**n):#i番目のライトの付け方
  c=bin(i) 
  j=0
  d=bool(True)
  for j in range(m):#電球jについて
    cnt_s=0
    for k in range(1,1+l[j][0]):#スイッチkの状態
      if bin(int(c,2) & int(bin(1<<(l[j][k]-1)),2))=="0b1":
        cnt_s=cnt_s+1
    if cnt_s%2!=p[j]:
      d=False
      print(d)
      
  if d==True:
    ans=ans+1
    j=j+1
  else:
    continue
  
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
array = np.zeros([M, N])
for i in range(M):
    l = list(map(int, input().split()))
    for j in l[1:]:
        array[i, j-1] = 1
p = np.array(list(map(int, input().split())))
count = 0
for i in range(1<<N):
    array_i = array.copy()
    for j in range(N):
        if i&(1<<j):
            array_i[:, j-1] = 0
    if sum((array_i.sum(1)%2 == p)&(array_i.sum(1)>0))==M:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
array = np.zeros([M, N])
for i in range(M):
    l = list(map(int, input().split()))
    for j in l[1:]:
        array[i, j-1] = 1
p = np.array(list(map(int, input().split())))
count = 0
for i in range(1<<N):
    array_i = array.copy()
    for j in range(N):
        if i&(j<<0):
            array_i[:, j-1] = 0
    if sum((array_i.sum(1)%2 == p)&(array_i.sum(1)>0))==M:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n, m = map(int,input().split())

k = []
for _ in range(m):
    k.append(list(map(int, input().split()))[0])

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

#総組み合わせ
ans = 1
for i in range(m):
    #各(k,p)に対する組み合わせ数
    com = 0
    #bit全探索（00000...0 ~ 11111...1)
    for j in range(2**k[i]):
        #onの数
        on = 0
        for h in range(0,k[i]):
            on += ((j >> h) & 1)
        #onの数%2とpの比較
        if on % 2 == p[i]:
            com += 1
    ans *= com

print(ans)

Submission status: Wrong Answer

Solution code:

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

swich = [0] * n

for i in range(m):
    _, *s = map(int, input().split())
    for j in range(len(s)):
        # swich[s[j] - 1] += 1 << (i)
        # swich[s[j] - 1] ^= 1 << (i)
        swich[s[j] - 1] |= 1 << (i)
    


p_list = list(map(int, input().split()))
p = 0
for i in range(m):
    # if p_list[i] == 1: 
    #     p += 1 << i
    p |= p_list[i] << i #上の処理と同じ

# print("++++++++++++++++++++++++")
# print(swich)
ans = 0
for i in range(1 << n):
    state_on_off = 0
    for index in range(m):
        if i >> index & 1 == 1:
            state_on_off ^= swich[index]
    if state_on_off == p:
        ans += 1
    # print(p, state_on_off,bin(i))
print(ans)

Submission status: Wrong Answer

Solution code:

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

swich = [0] * n

for i in range(m):
    _, *s = map(int, input().split())
    for j in range(len(s)):
        # swich[s[j] - 1] += 1 << (i)
        swich[s[j] - 1] ^= 1 << (i)
        # swich[s[j] - 1] |= 1 << (i)
    


p_list = list(map(int, input().split()))
p = 0
for i in range(m):
    # if p_list[i] == 1: 
    #     p += 1 << i
    p |= p_list[i] << i #上の処理と同じ

# print("++++++++++++++++++++++++")
# print(swich)
ans = 0
for i in range(1 << n):
    state_on_off = 0
    for index in range(m):
        if i >> index & 1 == 1:
            state_on_off ^= swich[index]
    if state_on_off == p:
        ans += 1
    # print(p, state_on_off,bin(i))
print(ans)

Submission status: Wrong Answer

Solution code:

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

swich = [0] * n

for i in range(m):
    _, *s = map(int, input().split())
    for j in range(len(s)):
        swich[s[j] - 1] += 1 << (i)
        # swich[s[j] - 1] ^= 1 << (i)
        # swich[s[j] - 1] |= 1 << (i)
    


p_list = list(map(int, input().split()))
p = 0
for i in range(m):
    if p_list[i] == 1: 
        p += 1 << i
    # p |= p_list[i] << i #上の処理と同じ

# print("++++++++++++++++++++++++")
# print(swich)
ans = 0
for i in range(1 << n):
    state_on_off = 0
    for index in range(m):
        if i >> index & 1 == 1:
            state_on_off ^= swich[index]
    if state_on_off == p:
        ans += 1
    # print(p, state_on_off,bin(i))
print(ans)

Submission status: Wrong Answer

Solution code:
"""
ビット全探索
"""
n, m = map(int, input().split())
k = [] ; s = []
ans = 0
#入力
for i in range(m) :
    data = list(map(int, input().split()))
    k.append(data[0])
    s.append(data[1:])
p = list(map(int, input().split()))

#ビット全探索
for i in range(2**n) :
    for r in range(m) :
        on = 0
        for j in range(n) :
            #j桁目が1であるかどうかを調べる
            #jがsに含まれているかどうか調べる
            if (i>>j) & 1 == 1 and j in s[r] :
                on += 1
        if on % 2 != p[r] :
            break
    else :
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import itertools
    n,m = map(int,input().split())
    lit = []
    for i in range(m):
        lit.append(list(map(int,input().split())))
    p = list(map(int,input().split()))
    stats = ((0,1) for i in range(n))
    ans = 0
    for stat in itertools.product(*stats):
        s = 0
        flg = 0
        for i in range(m):
            for j in range(lit[i][0]):
                s += stat[lit[i][j+1]-1]
            if s%2==p[i]:
                continue
            else:
                flg = 1
                break
        if flg==0:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    n, m = [int(x) for x in input().split()]
    s = []
    for _ in range(m):
        k, *r = [int(x) - 1 for x in input().split()]
        s.append(r)
    p = [int(x) for x in input().split()]
    ans = 0
    for i in range(2 ** n + 1): # mask
        ok = 1
        for j in range(m): # bulb
            pp = p[j]
            cnt = 0
            for ss in s[j]:
                if i & (1 << ss):
                    cnt += 1
            if cnt % 2 != pp:
                ok = 0
        ans += ok
    print(ans)

    


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
light=[]
ans=0
for i in range(m):
    List=list(map(int,input().split()))
    light.append(List)
p=list(map(int,input().split()))

for i in range(2**n):
    l=[0]*n
    for j in range(n):
        if (i>>j&1):
            l[j]=1
    cnt=0
    on=0
    for k in range(m):
        for o in range(1,len(light[k])):
            if (l[light[k][o]-1]==1):
                cnt+=1
        if cnt%2==p[k]:
            on+=1
    if on==m:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
ls3 = []
for i in range(M):
    ls1=list(map(int,input().split()))
    ls1.pop(0)
    ls3.append(ls1)
ls2 = list(map(int,input().split()))

ii = 0
for i in range(2**N):
    ls4 = [0]*M
    for j in range(N):
        if (i>>j&1):
            for k in range(M):
                if j in ls3[k]:
                    ls4[k] += 1
    
    if sum(ls4) == M:
        ii += 1

print(ii)

Submission status: Wrong Answer

Solution code:
import itertools as it
N, M = map(int, input().split())
A = []
for i in range (0, M):
	A.append(list(map(int, input().split())))

P = list(map(int, input().split()))

L = list(it.product([0,1], repeat = N))

combinations = 0
count = 0
summary = 0

for i in range (0, len(L)):
	count = 0
	for j in range (0,M):
		summary = 0
		for k in range (0, len(A[j])):
			summary+=L[i][A[j][k]-1]
		if summary%2 == P[j]:
			count = 1    
	if count == 0:
		combinations+=1

print(combinations)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    K = [[] for _ in range(M)]

    for j in range(M):
        k = list(map(int, input().split()))
        K[j] = set(k[1:])
    P = list(map(int, input().split()))
    count = 0
    l = list(range(1, N + 1))
    for i in range(1, N + 1):
        for comb in itertools.combinations(l, i):
            flag =0
            for j in range(M):  # denkyu
                temp = set(comb)
                if len(temp.intersection(K[j]) )% 2 != P[j]:
                    flag = 1
                    break
            if flag ==0:
                count +=1
    print(count)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = 0

for s in range(2**n):
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1, q[i][0]):
            w = q[i][j]
            if s >>(w-1) & 1 == 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
K = []
S = []
for m in range(M):
    l = list(map(int, input().split()))
    k = l.pop(0)
    K.append(k)
    S.append(l)
P = list(map(int, input().split()))
ans = 0
for n in range(1<<N):
    print(n)
    res = True
    for m in range(M):
        cnt = 0
        for q in range(K[m]):
            if n & (1<<S[m][q]-1):
                cnt += 1
        if cnt % 2 != P[m]:
            res = False
    if res:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
switch = [list(map(lambda x:int(x)-1, input().split()))[1:] for _ in range(m)]
rest = list(map(int, input().split()))
ans = 0
for bit in range(1<<n):
    on_sum = 0
    for j in range(m):
        for i in range(n):
            if bit >> i & 1 and i in switch[j]:
                on_sum += 1
        if on_sum % 2 != rest[j]:
            break
    else :
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
switch = [list(map(lambda x:int(x)-1, input().split()))[1:] for _ in range(m)]
rest = list(map(int, input().split()))
ans = 0
for bit in range(1<<n):
    on_sum = 0
    for j in range(m):
        for i in range(n):
            if bit >> i & 1 and i in switch[j]:
                on_sum += 1
        if on_sum % 2 != rest[j]:
            break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product

N, M = map(int, input().split())


def on_count(p):
    c = 0
    while p > 0:
        if p % 2 == 1:
            c += 1
        p //= 2
    return c


switches = []
for i in range(M):
    k, *sw = map(int, input().split())
    switches.append(sw)
P = list(map(int, input().split()))

total = 0
for pattern in product([0, 1], repeat=N):
    t = 0
    for k , indices in enumerate(switches):
        n_on = 0
        for idx in indices:
            if pattern[idx-1]:
                n_on += 1
        if n_on % 2 == P[k-1]:
            t += 1
    if t == M:
        total += 1
print(total)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
ls=[]
cnt,cnt2,ans=0,0,0
for i in range(M):
    ls1=list(map(int,input().split()))
    ls.append(list(ls1))
    ls1.clear()
lsp = list(map(int,input().split()))
#print(ls)
#print(lsp)
for i in range(2**N):
    flg = True
    for j in range(M):
        cnt = 0
        for k in range(1,len(ls[j])):
            if i >> ls[j][k] & 1:
                cnt += 1
        if cnt%2 != lsp[j]:
            flg = False
    if flg:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
n,m=map(int,input().split())
k=[]
for i in range(m):
    s=list(map(int,input().split()))
    s = list(map( lambda x:x-1,s))
    k.append(s)
p=list(map(int,input().split()))

ans=0

for bit in range(1<<n):
    cnt_swit=[0]*m
    for i in range(n):
        if bit>>i & 1:
            for j in range(m):
                if i in k[j]:
                    cnt_swit[j]+=1

    re_cnt_swit = list(map( lambda x:x%2,cnt_swit))
    tmp=0
    for i,cnt in enumerate(re_cnt_swit):
        if not cnt_swit[i]==0:
            if p[i]==cnt:
                tmp+=1
    if tmp==m:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
n,m=map(int,input().split())
k=[]
for i in range(m):
    s=list(map(int,input().split()))
    s = list(map( lambda x:x-1,s))
    k.append(s)
p=list(map(int,input().split()))

ans=0

for bit in range(1,1<<n):
    cnt_swit=[0]*m
    for i in range(n):
        if bit>>i & 1:
            for j in range(m):
                if i in k[j]:
                    cnt_swit[j]+=1
    cnt_swit = list(map( lambda x:x%2,cnt_swit))
    tmp=0
    for pi,cnt in zip(p,cnt_swit):
        if pi==cnt:
            tmp+=1
    if tmp==m:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
n,m=map(int,input().split())
k=[]
for i in range(m):
    s=list(map(int,input().split()))
    s = list(map( lambda x:x-1,s))
    k.append(s)
p=list(map(int,input().split()))

ans=0

for bit in range(1<<n):
    cnt_swit=[0]*m
    for i in range(n):
        if bit>>i & 1:
            for j in range(m):
                if i in k[j]:
                    cnt_swit[j]+=1
    cnt_swit = list(map( lambda x:x%2,cnt_swit))
    tmp=0
    for pi,cnt in zip(p,cnt_swit):
        if pi==cnt:
            tmp+=1
    if tmp==m:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
S = [[]for i in range(M)]
for i in range(M):
    k_s = list(map(int, input().split()))
    for j in range(len(k_s)-1):
        S[i].append(k_s[j+1])
p = list(map(int, input().split()))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
klist = []
swlist = []
ans = 0
for s in range(m):
	k,*sw = list(map(int,input().split()))#kとswを別々に入力
	klist.append(k) #<- kのリスト
	swlist.append(sw) #<- swのリスト
pwlist = list(map(int,input().split())) #pwのリスト

for i in range(2**n):#0~2**nまでの整数をカウントする(整数→ビットでの全探索)
	check = True
	for lump in range(m):#m個の電球についてカウントする
		cnt = 0
		for j in range(klist[lump]):#各スイッチ内の右シフト数をカウント	
			if (i>>swlist[lump][j])&1==1:#右にjシフトする
				cnt += 1#整数iのビットに対し、klistのスイッチがいくつonかをカウントする
		if cnt%2 != pwlist[lump]:#一つのスイッチ列でのカウント終了につき、判定する
			check = False#pwと互換性が1つでもなければFalseとする
	if check == True:#最後までFalseにならなければ組み合わせがあるということになる
		ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
klist = []
swlist = []
ans = 0
for s in range(m):
	k,*sw = list(map(int,input().split()))#kとswを別々に入力
	klist.append(k) #<- kのリスト
	swlist.append(sw) #<- swのリスト
pwlist = list(map(int,input().split())) #pwのリスト

for i in range(2**n):#0~2**nまでの整数をカウントする(整数→ビットでの全探索)
	check = True
	for lump in range(m):#m個の電球についてカウントする
		cnt = 0
		for j in range(klist[lump]):#各スイッチ内の右シフト数をカウント	
			if (i>>j)&1==1:#右にjシフトする
				cnt += 1#整数iのビットに対し、klistのスイッチがいくつonかをカウントする
		if cnt%2 != pwlist[lump]:#一つのスイッチ列でのカウント終了につき、判定する
			check = False#pwと互換性が1つでもなければFalseとする
	if check == True:#最後までFalseにならなければ組み合わせがあるということになる
		ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
klist = []
swlist = []
ans = 0
for s in range(m):
	k,*sw = list(map(int,input().split()))#kとswを別々に入力
	klist.append(k) #<- kのリスト
	swlist.append(sw) #<- swのリスト
pwlist = list(map(int,input().split())) #pwのリスト

for i in range(2**n):#0~2**nまでの整数をカウントする(整数→ビットでの全探索)
	check = True
	cnt = 0
	for lump in range(m):#m個の電球についてカウントする
		for j in range(klist[lump]):#各スイッチ内の右シフト数をカウント	
			if (i>>j)&1==1:#右にjシフトする
				cnt += 1#整数iのビットに対し、klistのスイッチがいくつonかをカウントする
		if cnt%2 != pwlist[lump]:#一つのスイッチ列でのカウント終了につき、判定する
			check = False#pwと互換性が1つでもなければFalseとする
	if check == True:#最後までFalseにならなければ組み合わせがあるということになる
		ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
N,M = list(map(int,input().split()))
k_lis = []
for i in range(M):
    k_lis.append(list(map(int,input().split())))
P = list(map(int,input().split()))
switch_list = list(itertools.product('01',repeat = N))
ans = 0
sub = 0

for sl in range(len(switch_list)):#スイッチ全探索
    if  '1' in  (switch_list[sl]):#スイッチが少なくとも一つ点灯
        flag = 0
        for i in range(M):#電球１つ１つを探索していく
            counter = 0
            for j in range(1,k_lis[i][0]+1):
                if switch_list[sl][k_lis[i][j]-1] == '1' :
                    counter += 1
                    
            if counter %2 != P[i]:
                flag = 1
                break
        if flag == 0:    
            ans += 1
print(ans)

Submission status: Wrong Answer

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

for i in range(2 ** n):
  lights = []
  for j in range(n+1):
    if ((i >> j) & 1):
      lights.append(j+1)
      
  for inde, l in enumerate(l_list):
    if len(set(l[1:]) & set(lights)) % 2 != p[inde-1]:
      break
  else:
    output += 1
print(output)

Submission status: Wrong Answer

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

ans = 0
for bit in range(1<<N):
    count = [0]*M
    for i in range(N):
        if (bit >> i) & 1:
            for a in range(M):
                if i in ks[a][1:]:
                    count[a] +=1
    a = 0
    for i in range(M):
        if count[i] % 2 == p[i]:
            a += 1
            if a == M:
                ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, M = list(map(int, input().split(" ")))
S = []
for i in range(M):
    ks = list(map(int, input().split(" ")))
    S.append(ks[1:])
P = list(map(int, input().split(" ")))

switchMap = []
for i in range(N):
    switchMap.append([])
for i, s in enumerate(S):
    for ss in s:
        switchMap[ss-1].append(i)

count = 0
for i in range(pow(2, N)):
    switches = bin(i).replace("0b", "").zfill(N)
    light = [0] * M
    for j, switch in enumerate(switches):
        if switch == '1':
            for s in switchMap[j]:
                light[s] += 1

    flag = True
    for j, l in enumerate(light):
        if l % 2 != P[j]:
            flag = False
            break

    if flag:
        print(switches)
        count += 1

print(count)

Submission status: Wrong Answer

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

ans = 0

for i in range(1<<N):
    for r in range(M):
        on_sum = 0
        for j in range(N):
            if (i >> j) & 1 and j in lamps[r]:
                on_sum += 1
        if on_sum % 2 != p[r]:
            break
    else:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0

for i in range(1<<N):
    for r in range(M):
        on_sum = 0
        for j in range(N):
            if (i >> j) & 1 and j in lamps[r][1:]:
                on_sum += 1
        if on_sum % 2 != p[r]:
            break
    else:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 0

for bit in range(1<<N):
    for lump in range(M):
        on_lump = 0
        for i in range(N):
            if (bit >> i) & 1 and i in k[lump][1:]:
                on_lump += 1
        if on_lump % 2 != p[lump]:
            break
    else:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
f=lambda:[*map(int,input().split())]
n,m=f()
S=[f()[1:] for _ in [0]*m]
p=f()
print(sum(all(sum(i>>-~k for k in S[j])%2==p[j] for j in range(m)) for i in range(2**n)))

Submission status: Wrong Answer

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

ans = 0

for bit in range(1<<n):
  on = 0
  for i in range(m):
    numon = 0
    k = k_s[i][0]
    s = k_s[i][1:]
    for j in range(k):
      mask = 1<<s[j]
      if mask&bit:
        numon += 1
    if numon%2 == p[i]:
      on += 1
  if on == m:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import combinations
n,m = map(int,input().split())
card =[[0]*n for _ in range(m)]
for i in range(m):
    switch = list(map(int,input().split()))[1:]
    for k in switch:
        card[i][k-1] = 1
##どこに繋がっているかを配列で表現

#print(card)


ans =list(map(int,input().split()))
cnt=0
from itertools import combinations
##全通りを調べる
for epoch in range(1,n+1):
    
    for j in combinations(range(1,n+1),epoch):
        sco =[]
        for lisa in card:##一つずつの照明について調べる
            score =0
            for l in j:
                score += lisa[l-1]
                
            sco.append(score)
        #print(sco)
        if list(np.array(sco)%2) == ans:
            cnt+=1
            
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import product
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(m)]
    SS = []
    for s in S:
        tmp = [False] * n
        for i in range(s[0]):
            tmp[i - 1] = True
        SS.append(tmp)
    P = list(map(int, input().split()))

    res = 0
    for pattern in product([0, 1], repeat=n):
        total = 0
        for i in range(m):
            s = SS[i]
            cnt = 0
            for idx, p in enumerate(pattern):
                if p == 1 and s[idx]:
                    cnt += 1
            if cnt % 2 == P[i]:
                total += 1
        if total == m:
            res += 1
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

ans = 0
for bit in range(2**n):
    check = 0
    for k, p in zip(k_list, p_list):
        count = 0
        for i in range(n):
            if bit & (1 << i):
                if i in k:
                    count += 1
        if (count%2) == p:
            check += 1
    if check == m:
        ans += 1
        
print(ans)

Submission status: Wrong Answer

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

ans = 0
for bit in range(2**n):
    check = True
    for k, p in zip(k_list, p_list):
        if check:
            count = 0
            for i in range(n):
                if bit & (1 << i):
                    if i in k:
                        count += 1
            if (count%2) != p:
                check = False
    if check:
        ans += 1
        
print(ans)

Submission status: Wrong Answer

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

ans = 0
for bit in range(2**n):
    check = True
    for k, p in zip(k_list, p_list):
        count = 0
        for i in range(n):
            if bit & (1 << i):
                if i in k:
                    count += 1
        if (count%2) != p:
            check = False
            break
    if check:
        ans += 1
        
print(ans)

Submission status: Wrong Answer

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

def rec(A, c):
  if len(A) == n:
    count_m = 0
    for l in range(m):
      list_m = []
      list_k = k[l]
      count = 0
      for j in range(list_k[0]):
        if A[j - 1] == 1:
          count += 1
      if p[l] == (count%2):
        count_m += 1
    if(count_m == m):
      c += 1
    return c
  
  for i in range(2):
    A.append(i)
    c = rec(A, c)
    A.pop()

  return c

print(rec([], check))

Submission status: Wrong Answer

Solution code:
import itertools
count =0
ans=0
n,m = map(int,input().split())
num=[0,1]
pattern = list(itertools.product(num, repeat=n))
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)
    onoff = [0]*m
    for j in range(m):
        for k in lists[j][1:]:
            if switches[k-1] == 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())
num=[0,1]
pattern = list(itertools.product(num, repeat=n))
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)
    onoff = [0]*m
    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]*n)
pattern.append([1]*n)

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)
    onoff = [0]*m
    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]*n)
pattern.append([1]*n)

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)