Problem:


Score : 400 points

Problem Statement

There are two persons, numbered 0 and 1, and a variable x whose initial value is 0.
The two persons now play a game.
The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N):

Person S_i does one of the following:

Replace x with x \oplus A_i, where \oplus represents bitwise XOR.

Do nothing.

Person 0 aims to have x=0 at the end of the game, while Person 1 aims to have x \neq 0 at the end of the game.

Determine whether x becomes 0 at the end of the game when the two persons play optimally.

Solve T test cases for each input file.

Constraints

1 \leq T \leq 100

1 \leq N \leq 200

1 \leq A_i \leq 10^{18}

S is a string of length N consisting of 0 and 1.

All numbers in input are integers.

Input

Input is given from Standard Input in the following format.
The first line is as follows:

T

Then, T test cases follow.
Each test case is given in the following format:

N
A_1 A_2 \cdots A_N
S

Output

For each test case, print a line containing 0 if x becomes 0 at the end of the game, and 1 otherwise.

Sample Input 1

3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000

Sample Output 1

1
0
0

In the first test case, if Person 1 replaces x with 0 \oplus 1=1, we surely have x \neq 0 at the end of the game, regardless of the choice of Person 0.

In the second test case, regardless of the choice of Person 1, Person 0 can make x=0 with a suitable choice.



Sample input:
3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000


Sample output:
1
0
0

Submission status: Wrong Answer

Solution code:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log, floor
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

t = INT()

while(t!=0):
    n =INT()

    a = LIST()

    s = input()

    ones = []
    zeros = []

    for i, ch in enumerate(s):
        if(ch=='0'):
            zeros.append(a[i])
        else:
            ones.append(a[i])

    oUtil = ['?']*61
    zUtil = ['?']*61

    for j in range(61):
        flag = 0
        for el in ones:
            if((el>>j)&1):
                flag = 1
                break
        if(flag==0):
            oUtil[j] = '0'


    for j in range(61):
        flag = 0
        for el in zeros:
            if((el>>j)&1):
                flag = 1
                break
        if(flag==0):
            zUtil[j] = '0'

    ans = 0
    for i in range(61):
        if(oUtil[i]=='?' and zUtil[i]=='0'):
            ans = 1
            break

    print(ans)

    t-=1

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for _ in range(3*n)]
for _ in range(n):
	print(1)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
from operator import itemgetter


def sweep(l):
    result = set()
    s = set(l)
    while s:
        a = max(s)
        b = 1 << (a.bit_length() - 1)
        s.remove(a)
        s = {t ^ b if t >= b else t for t in s}
        s.discard(0)
        result.add(b)
    return result


t = int(input())
buf = []
for _ in range(t):
    n = int(input())
    aaa = list(map(int, input().split()))
    s = input()

    if s[-1] == '1':
        buf.append(1)
        continue

    grp = [list(map(itemgetter(1), itr)) for c, itr in groupby(zip(s, aaa), key=itemgetter(0))]
    if s[0] == '0':
        grp.insert(0, [])
    grp.reverse()

    is_ok = True

    for l0, l1 in zip(grp[0::2], grp[1::2]):
        s0 = sweep(l0)
        s1 = sweep(l1)
        if s1.difference(s0):
            buf.append(1)
            is_ok = False
            break

    if is_ok:
        buf.append(0)

print('\n'.join(map(str, buf)))

Submission status: Wrong Answer

Solution code:
import sys 

input = sys.stdin.readline

def main():
  t = int(input().rstrip())
  
  for i in range(t):
    n = int(input().rstrip())
    a = list(map(int, input().rstrip().split()))
    s = input()
    x = 0
    
    if s[-1] == "1":
      print(1)
    else:
      for k in range(n):
        if s[k] == "1" and x ^ int(a[k]) != 0:
          x = x ^ int(a[k])
        if s[k] == "0" and x ^ int(a[k]) == 0:
          x = x ^ int(a[k])
      if x == 0:
        print(0)
      else:
        print(1)
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
T = int(input())

for case in range(T):
  N = int(input())
  A = list(map(int,input().split()))
  S = str(input())
  att = set([]); blo = set([])
  for i in range(N):
    if S[i] == "1": #攻撃側人1
      for j in range(70):
        if A[i]>>j&1 == 1:
          att.add(j)
    else: #守り側人0
      for j in range(70):
        if A[i]>>j&1 == 1:
          blo.add(j)
  #print(att,blo)
  if att.issubset(blo):
    print("0")
  else:
    print("1")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for _ in range(3*n)]
for _ in range(3):
	print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for _ in range(3*n)]
for _ in range(3):
	print(0)

Submission status: Wrong Answer

Solution code:
T = int(input())

for case in range(T):
  N = int(input())
  A = list(map(int,input().split()))
  S = str(input())
  att = set([]); blo = set([])
  for i in range(N):
    if S[i] == "1": #攻撃側人1
      for j in range(70):
        if A[i]>>j&1 == 1:
          att.add(j)
    else: #守り側人0
      for j in range(5):
        if A[i]>>j&1 == 1:
          blo.add(j)
  #print(att,blo)
  if att.issubset(blo):
    print("0")
  else:
    print("1")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba
import math

def run():
    T = int(input())
    for i in range(T):
        N = int(input())
        A = list(map(int, sysread().split()))
        S = list(input())
        #print(A, S)
        maxbit = math.ceil(math.log2(max(A)))
        ok = True
        for shift in range(maxbit):
            checked = False
            for index in range(N-1, -1, -1):
                #print('shift', shift, 'index',index)
                if S[index] == '1':
                    checked = True
                    if (A[index] >> shift) % 2:
                        ok = False
                        break
                    else:
                        break
            if checked:
                break
        if not ok:
            print(1)
        else:
            print(0)

if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split())) 
    s = input()
    ans = 0

    for i in range(len(a)):
        if s[i] == '0':
            if bin(ans^a[i]) == 0:
                continue
            else:
                if ans == 0:
                    continue
                else:
                    ans = bin(ans^a[i])
        else:          
            if bin(ans^a[i]) != 0:
                ans = bin(ans^a[i])  
            else:
                continue
        ans = int(ans, 0)
    if ans == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for _ in range(3*n)]
print(3)

Submission status: Wrong Answer

Solution code:
T = int(input())

for case in range(T):
  N = int(input())
  A = list(map(int,input().split()))
  S = str(input())
  att = set([]); blo = set([])
  for i in range(N):
    if S[i] == "1": #攻撃側人1
      for j in range(5):
        if A[i]>>j&1 == 1:
          att.add(j)
    else: #守り側人0
      for j in range(5):
        if A[i]>>j&1 == 1:
          blo.add(j)
  #print(att,blo)
  if att.issubset(blo):
    print("0")
  else:
    print("1")

Submission status: Wrong Answer

Solution code:
t = int(input())

for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    s = input()
    x = 0
    for j in range(n):
        if s[j] == "1":
            if x ^ a[j] != 0:
                x = x ^ a[j]
        if s[j] == "0":
            if x ^ a[j] == 0:
                x = x ^ a[j]
    #print(x)
    if x == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
def xor_gauss_jordan(A):
    """掃き出し法でジョルダン標準形を求める"""
    cnt_row = len(A)
    cnt_col = len(bin(max(A))[2::])
 
    rank = 0
    for col in range(cnt_col):
        # ピボットを探す
        pivot = -1
        for row in range(rank, cnt_row):
            if A[row] & 2**(cnt_col - col - 1):
                pivot = row
                break
 
        #  ピボットがない場合は次の列に
        if pivot == -1:
            continue
 
        # 行をスワップする
        A[pivot], A[rank] = A[rank], A[pivot]
 
        # ピボットのある列の値がすべて0になるように掃き出す
        A_rank = A[rank]
        for row in range(cnt_row):
            if row != rank and A[row] & 2**(cnt_col - col - 1):
                A[row] ^= A[rank]
        rank += 1
 
    return A


def compress(string):
    """文字列をランレングス圧縮する
    例) string = "aabccaaabb" -> [(2, a), (1, b), (2, c), (3, a), (2, b)]
    """
    string = string + "#" # 番兵
    n = len(string)
    begin, end, cnt = 0, 1, 1
    ans = []
    while end < n:
        if string[begin] == string[end]:
            end, cnt = end + 1, cnt + 1
        else:
            ans.append((string[begin], cnt))
            begin, end, cnt = end, end + 1, 1
    return ans


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s = input()

    s = compress(s)
    r = n
    memo_0 = set()
    flag = False
    for turn, cnt in s[::-1]:
        tmp = xor_gauss_jordan(a[r - cnt:r])
        r -= cnt
        if turn == "1":
            for val in tmp:
                for min_ in memo_0:
                    if val & min_ == min_:
                        val -= min_
                if val != 0:
                    flag = True
        else:
            for val in tmp:
                memo_0.add(val)

    if flag:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
t=int(input())
while t:
	t-=1
	n=int(input())
	a=list(map(int,input().split()))
	s=input()
	o=1
	x=0
	if o not in a:
		print(0)
		#print("if block")
	else:
		for i in range(n):
			if s[i]=='1':
				if a[i]==1:
					x=x^1
			elif s[i]=='0':
				if a[i]==1:
					if x==1:
						x=x^1
		print(x)

Submission status: Wrong Answer

Solution code:
t=int(input())
l1=[]
l2=[]
x=0
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    s=input()
    for j in range(n):
        if s[j]=="1":
            if l[j]!=x:
                x=x^l[j]
        if s[j]=="0":
            if l[j]==x:
                x = x ^ l[j]
    l1.append(x)
for i in l1:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for _ in range(3*n)]
print(0)

Submission status: Wrong Answer

Solution code:
import sys 

input = sys.stdin.readline

def main():
  t = int(input().rstrip())
  
  for i in range(t):
    n = int(input().rstrip())
    a = list(map(int, input().rstrip().split()))
    s = input().rstrip()
    x = 0
    
    if s[-1] == "1":
      print(1)
    else:
      for k in range(n):
        if s[k] == "1" and x == 0 and x ^ int(a[k]) != 0:
          x = x ^ int(a[k])
        if s[k] == "0" and x ^ int(a[k]) == 0:
          x = x ^ int(a[k])
      if x == 0:
        print(0)
      else:
        print(1)
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import sys 

input = sys.stdin.readline

def main():
  t = int(input().rstrip())
  
  for i in range(t):
    n = int(input().rstrip())
    a = list(map(int, input().rstrip().split()))
    s = input().rstrip()
    x = 0
    
    if s[-1] == "1":
      print(1)
    else:
      for k in range(n):
        if s[k] == "1" and x ^ int(a[k]) != 0:
          x = x ^ int(a[k])
        if s[k] == "0" and x ^ int(a[k]) == 0:
          x = x ^ int(a[k])
      if x == 0:
        print(0)
      else:
        print(1)
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math

def main():
    T = int(input())
    for i in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()
        # print(S,A)
        num0 = set()
        num1 = set()
        digits0 = [0] * 60# 人0の手番のときの各桁の和
        digits1 = [0] * 60# 人1の手番のときの各桁の和
        for j in range(N):
            if S[j] == '0':
                num0.add(A[j])
                for k in range(60):
                    digits0[k] += (A[j] >> k)&1
            else:
                num1.add(A[j])
                for k in range(60):
                    digits1[k] += (A[j] >> k)&1
        
        flag = True
        # それぞれのmax(A[i])の対数をとって1の方が大きいと１がかつ
        if math.log2(max(digits0)+1) < math.log2(max(digits0)+1):
            print(1)
        elif len(digits0) < len(digits1):# 個数の観点から
            print(1)
        else:
            # 桁の観点から
            for k in range(60):
                if digits0[k] == 0 and digits1[k] > 0:
                    print(1)
                    flag = False
                    break
            if flag:
                print(0)
        
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (
    acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
    sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


t = inp()

for _ in range(t):
    n = inp()
    a = inlist()
    s = input()
    x = 0
    for i in range(n):
        person = s[i]
        if person == "0":
            xr = x ^ a[i]
            f = 0
            for j in range(i+1, n):
                if s[j] == "0":
                    if xr == a[j]:
                        f = 1
                        break
            if f == 1 or xr == 0:
                x = xr
        elif person == "1":
            xr = x ^ a[i]
            flag = 1
            for j in range(i+1, n):
                if s[j] == "0":
                    if a[j] == xr:
                        flag = 0
                        break

            if flag == 1 or x == 0:
                x = x ^ a[i]
        #print("Value: ", x)

    print(x)

Submission status: Wrong Answer

Solution code:
t = int(input())
N = []
A = []
S = []
total = []
sum = 0
count = 0
sCount = 0
for i in range(t):
    N.append(int(input()))
    A.append(list(map(int, input().split()))) 
    S.append(input())



for a in A:
    for b in a: 
        if sum ^ b == 0:
            if S[count][sCount] == "0":
                sum ^= b
            else:
                continue
        else:
            if S[count][sCount] == "0":
                continue
            else:
                sum ^= b
        sCount += 1
    count += 1
    total.append(sum)
    sum = 0
    sCount = 0

for to in total:
    if to == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split())) 
    s = input()
    ans = 0

    for i in range(len(a)):
        if s[i] == '0':
            if bin(ans^a[i]) == 0:
                continue
            else:
                if ans == 0:
                    continue
                else:
                    ans = bin(ans^a[i])
        else:          
            if bin(ans^a[i]) == 1:
                continue
            else:
                if ans != 0:
                    continue
                else:
                    ans = bin(ans^a[i])  
        ans = int(ans, 0)
    if ans == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
for _ in range(int(input())):
    n= int(input())
    L=list(map(int,input().split()))
    s=list(input().rstrip())
    x=0
    if n==1:
        if s[0]=='0':
            print('0')
        else:
            if L[0]==0:
                print('0')
            else:
                print('1')
                
    else:
        d={'0':[],'1':[]}
        for i in range(n):
            if s[i]=='0':
                d[s[i]].append(L[i])
            else:
                d[s[i]].append(L[i])
        for i in range(n):
            val = x^L[i]
            if s[i]=='1':
                if val != 0:
                    x = val
        
        if x in d['0']:
            x=0

        if x==0:
            print('0')
        else:
            print('1')

Submission status: Wrong Answer

Solution code:
t = int(input())

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split())) 
    s = input()
    ans = 0

    for i in range(len(a)):
        if s[i] == '0':
            if bin(ans^a[i]) == 0:
                continue
            else:
                if ans == 0:
                    continue
                else:
                    ans = bin(ans^a[i])
        else:          
            if bin(ans^a[i]) == 1:
                continue
            else:
                ans = bin(ans^a[i])  
        ans = int(ans, 0)
    if ans == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba
import math

def run():
    T = int(input())
    for i in range(T):
        N = int(input())
        A = list(map(int, sysread().split()))
        S = list(input())
        #print(A, S)
        maxbit = math.floor(math.log2(max(A)))
        ok = True
        for shift in range(maxbit):
            for index in range(N-1, -1, -1):
                #print('shift', shift, 'index',index)
                if S[index] == '1':
                    if (A[index] >> shift) % 2:
                        ok = False
                    break
            if not ok:
                break
        if not ok:
            print(1)
        else:
            print(0)

if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
lineNum = int(input())
lines = []
for i in range(3 * lineNum):
    lines.append(input())
for i in range(lineNum):
    start = 3 * i
    end = 3 * (i + 1)
    case = lines[start:end]
    nums = case[1].split()
    persons = case[2]
    x = 0
    for i, person in enumerate(persons):
        case[1]
        if person == "0":
            if x == 1 and int(nums[i]) % 2 == 0:
                x = 1
            else: 
                x = 0
        elif person == "1":
            if x == 0 and int(nums[i]) % 2 == 0:
                x = 0
            else:
                x = 1
    print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
for i in range(N):
    x = 0
    n = int(input())
    lst = list(map(int, input().split()))
    p = input()
    for i in p:
        if i == '1':
            if x ^ lst[0] != 0:
                x = (x ^ lst.pop(0))
            else:
                lst.pop(0)
        else:
            if x ^ lst[0] == 0:
                x = (x ^ lst.pop(0))
            else:
                lst.pop(0)
    ans.append(x)


for i in ans:
    if i == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
T=int(input())
for t in range(T):
    N = int(input())
    A=list(map(int,input().split()))
    S = input()
    P0=[0]*60
    P1=[0]*60
    for i,c in enumerate(S):
        if i == len(S)-1 and c == "1":
            print('1')
            break
        if c == "0":
            for i,v in enumerate(str(format(A[i],'b'))[::-1]):
                if v == '1':
                    P0[i]=1
        else:
            for i,v in enumerate(str(format(A[i],'b'))[::-1]):
                if v == '1':
                    P1[i]=1
    flag = True
    for a,b in zip(P0,P1):
        if a != b:
            flag = False
    if flag:
        print('0')
    else:
        print('1')

Submission status: Wrong Answer

Solution code:
def zero(x,a):
    if a == 0:
        return x
    else:
        x = x^a
        return x

def notzero(x,a):
    if a == 0:
        x = x^a
        return x
    else:
        return x

T = int(input())

for t in range(T):
    N = int(input())
    A= list(map(int, input().split()))
    S = list(input())
    x = 0
    for i in range(len(S)):
        a = A[i]
        if S[i] == 1:
            x = notzero(x,a)
        else:
            x = zero(x,a)
    if x == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
T = int(input())
print(T)

Submission status: Wrong Answer

Solution code:
num=int(input().rstrip())
for i in range(num):
    num_i=int(input().rstrip())
    line=input().rstrip().split()
    main=[]
    for j in range(num_i):
        main.append(int(line[j]))
    jyunnjyo=input().rstrip()
    mains=[]
    flag=0
    for k in reversed(range(num_i)):
        if main[k]%2==1:
            mains.append(k)
            flag=1
        if flag==1:
            break
    if mains==[]:
        print(0)
    else:
        print(jyunnjyo[mains[0]])

Submission status: Wrong Answer

Solution code:
from itertools import  combinations
t = int(input())
for i in range(t):
    N = int(input())
    A = [x for x in map(int,input().split())]
    C = [i[0] ^ i[1] for i in combinations(A,2)]
    S = input()
    x = 0
    i = 0
    while i < N:
        if S[i] == "1":
            temp = x
            x = x ^ A[i] if x not in A[i:] and x not in C else temp
        if S[i] == "0":
            temp = x
            x = x ^ A[i] if x in A[i:] and x in C else temp
        i+= 1
    print(0 if x == 0 else 1)

Submission status: Wrong Answer

Solution code:
T = int(input())

for _ in range(T):
    N = int(input())
    As = list(map(int, input().split()))
    S = input()
    possible_xor = []
    if S[-1] == '1':
        print(1)
        continue
    flg = True
    for c, A in reversed(list(zip(S, As))):
        if c == '0':
            for xor in possible_xor:
                if A & xor:
                    A ^= xor
            for i in range(len(possible_xor)):
                if A & possible_xor[i]:
                    possible_xor[i] ^= A
            possible_xor.append(A)
        else:
            for xor in possible_xor:
                if A & xor:
                    A ^= xor
            if A != 0:
                flg = False
                break
    if flg:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
for i in range(N):
    x = 0
    n = int(input())
    lst = list(map(int, input().split()))
    p = input()
    for i in p:
        if i == '1':
            if x ^ lst[0] != 0:
                x = (x ^ lst.pop(0))
        else:
            if x ^ lst[0] == 0:
                x = (x ^ lst.pop(0))
    ans.append(x)


for i in ans:
    if i == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    T = int(readline())
    for _ in range(T):
        N = int(readline())
        A = list(map(int, readline().split()))
        S = list(readline()[:-1])
        human1 = set(); human0 = set()
        for i, s in enumerate(S):
            if s == '1':
                human1.add(A[i])
            else:
                human0.add(A[i])
        if len(human1) == 0:
            print(0)
            continue
        if len(human0) == 0:
            print(1)
            continue
        nexts = deque(list(human1))
        flag = False
        for p in range(pow(10, 6)):
            nxt = nexts.popleft()
            for h0 in human0:
                tmp = nxt^h0
                if tmp in human0:
                    human0.add(nxt)
                    break
                elif tmp in human1:
                    print(1)
                    flag = True
                    break
                else:
                    nexts.append(tmp)
            if flag:
                break
            if len(nexts) == 0:
                print(0)
                break

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())

def main():
  t = int(input())
  for _ in range(t):
    n = int(input())
    a = LI()
    s = input()
    x = 0
    for i in range(n):
      if s[i] == '1' and a[i] != x:
        ans = 1
        x = x ^ a[i]
      elif s[i] == '0' and a[i] == x:
        ans = 0
    print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
T = int(input())

def canZero():
    _ = int(input())
    A = list(map(int, input().split()))[::-1]
    S = list(map(int, input()))[::-1]

    for d in range(100):
        mask = 1 << d
        for s, a in zip(S, A):
            if (mask & a) != 0:
                if s == 1:
                    return False
                break
    return True

for _ in range(T):
    print('0' if canZero() else '1')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

t = int(input())
num_list = []
for i in range(t):
    n = int(input())
    num_list = list(map(int, input().split()))
    s = input()
    str_list = list(s)
    x = 0
    num_list.reverse()
    str_list.reverse()
    for j in range(n):
        if num_list[j]%2 == 1:
            if str_list[j] == '0':
                x = 0
                break
            else:
                x = 1
                break
        else:
            continue
    print(x)
            
    
    # print(n)
    # print(num_list)
    # print(str_list)

Submission status: Wrong Answer

Solution code:
import string

x = 0
t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    s = input()
    for j in range(len(s)):
        if(s[j]=='0' and a[j]^x==0):
            x = x^a[j]
        elif(s[j]=='1' and a[j]^x!=0):
            x = x^a[j]
    if(x==0):
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
T = int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = list(input())
    #
    A_0 = [0] * N
    A_1 = [0] * N
    for i, Si in enumerate(S):
        if Si == '0':
            A_0[i] = Si
        else:
            A_1[i] = Si
    #
    ORs = []
    Si_prev = '1'
    OR_temp = 0
    for i, Si in enumerate(S):
        if Si != Si_prev:
            ORs.append(OR_temp)
            OR_temp = 0
        #
        OR_temp |= A[i]
        Si_prev = Si
    else:
        ORs.append(OR_temp)
    #
    # print("#", ORs)
    ans = 0
    for i, OR_tmp in enumerate(ORs):
        if i == 0:
            ans |= OR_tmp
        else:
            ans &= (~OR_tmp)
    #
    if ans == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3


def num2bin(n):
    return tuple(int(d) for d in "{:070b}".format(n))


def can_reach_zero(n, bs, s):
    bins = [num2bin(b) for b in bs]
    max_len = len(bins[0])
    score = [[0 for _ in range(max_len)] for _ in range(2)]
    for i, player in enumerate(s):
        for j, c in enumerate(bins[i]):
            if c == 1:
                score[player][j] += 1
    for s0, s1 in zip(score[0], score[1]):
        if s0 < s1:
            return False
    else:
        return True


def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        bs = [int(b) for b in input().split()]
        s = [int(d) for d in input()]
        if can_reach_zero(n, bs, s):
            print(0)
        else:
            print(1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
T = int(input())
x = 0

for i in range(T): # testcase
    N = int(input())
    A = list(map(int,input().split()))
    S = input()

    for j in range(N): # round
        turn = int(S[j])
        if turn == 0:
            if x ^ A[j] == 0:
                x = 0
            else:
                continue
        if turn == 1:
            if x ^ A[j] != 0:
                x = x ^ A[j]
            else:
                continue
    
    if x == 0:
        print(x)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
T = int(input())

for t in range(T):
  x = 0
  N = int(input())
  A = list(map(int, input().split()))
  S = input()

  # i番目の人は、x^Aするかどうかを考える
  # Sのi番目が0ならx=0になるときだけ変更する、1ならx!=0になるときだけ変更する
  
  for i in range(N):
    if S[i] == "0":
      if x ^ A[i] == 0:
        x = x ^ A[i]
      
    else:
      if x ^ A[i] != 0:
        x = x ^ A[i]
  if x == 0:
    print(0)
  else:
    print(1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def main():
    T = int(input())
    for i in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()
        # print(S,A)
        digits0 = [0] * 60# 人0の手番のときの各桁の和
        digits1 = [0] * 60# 人0の手番のときの各桁の和
        for j in range(N):
            if S[j] == '0':
                for k in range(60):
                    digits0[k] += (A[j] >> k)&1
            else:
                for k in range(60):
                    digits1[k] += (A[j] >> k)&1
        flag = True
        for k in range(60):
            if digits0[k] == 0 and digits1[k] > 0:
                print(1)
                flag = False
                break
        if flag:
            print(0)
        
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
T = int(input())

def canZero():
    N = int(input())
    A = list(map(int, input().split()))[::-1]
    S = list(map(int, input()))[::-1]

    for d in range(64):
        mask = 1 << d
        for s, a in zip(S, A):
            if (mask & a) != 0:
                if s == 1:
                    return False
                break
    return True

for _ in range(T):
    print('0' if canZero() else '1')