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:
T=int(input())
for t in range(T):
    N=int(input())
    A=list(map(int,input().split()))[::-1]
    S=input()
    S=[1 if c=='1' else 0 for c in S][::-1]
    d=[0]*60
    r=0
    for i in range(N):
        s=bin(A[i])[2:].zfill(60)
        if S[i]:
            s1=set([d[j] for j in range(60) if s[j]=='1'])
            s2=set([d[j] for j in range(60) if s[j]=='0' and d[j]])
            if 0 in s1 or len(s1&s2):
                r=1
        else:
            for j,c in enumerate(s):
                if c=='1':
                    d[j]+=2**i
    print(r)

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()
    key = int(s[-1])
    wset = {0}
    setlist = []#逆順になる
    manlist = []#逆順になる
    for j in range(n):
        temp = int(s[-(j+1)])
        if(temp == 0):
            if(temp == key):
                tempset = set()
                for k in wset:
                    tempset.add(k ^ a[-(j+1)])
                wset = wset | tempset
            else:
                setlist.append(wset)
                manlist.append(key)
                key = temp
                wset = {0, a[-(j+1)]}
    setlist.append(wset)
    manlist.append(key)
    if(manlist[0] == 1): print(1)
    else:
        for i in range(len(manlist)):
            if(manlist[i] == 0):
                if(i+1 <len(manlist)):
                    if(setlist[i+1] - setlist[i] != set()):
                        print(1)
                        break
                else:
                    print(0)

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 = []
    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:
                val2 = 0
                for min_ in memo_0:
                    if val & min_ == min_:
                        val2 |= min_
                if val != val2:
                    flag = True
        else:
            for val in tmp:
                memo_0.append(val)
                memo_0 = xor_gauss_jordan(memo_0)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    s = input()
    lsa = np.zeros((200,60))
    if s[-1] == "1":
        print(1)
        continue
    for i in range(n-1,-1,-1):
        b = format(a[i], '060b')
        if s[i] == "0":
            for j in range(60):
                lsa[i][j] = int(b[j])
            if s[i-1] == "1":
                ra = np.linalg.matrix_rank(lsa)
                # print("ra=",ra)
        else:
            for j in range(60):
                lsa[i][j] = int(b[j])
            rb = np.linalg.matrix_rank(lsa)
            # print("rb=",rb)
            if rb != ra:
                print(1)
                break
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
T = int(input())
N = []
A = []
S = []
for i in range(T):
    N.append(int(input()))
    A.append(list(map(int, input().split())))
    S.append(list(input()))


def culculate(x, a):
    return(x ^ a)


for i in range(T):
    x = 0
    wait_flag = False
    for n in range(N[i]):
        # print(x)
        player = S[i][n]
        result_calc = culculate(x, A[i][n])
        if(player == "0"):
            # print(wait_flag)
            if(x != 0):
                if(result_calc == 0):
                    x = result_calc
                elif (wait_flag == True):
                    x = x
                elif(result_calc in A[i][n+1:]):
                    wait_flag = True
                    x = result_calc
                # if(result_calc == 0):
                else:
                    x = result_calc
        if(player == "1"):
            if(x == 0):
                # if(result_calc != 0):
                x = result_calc
    print("0" if x == 0 else "1")
    # print()

Submission status: Wrong Answer

Solution code:
t = int(input())
l = [list(map(int,input().split())) for _ in range(t*3)]

ans=[]
n = []
a = []
s = []
#n,a,sに代入
for i in range(t*3):
    if i%3==0:
        n.append(l[i]) 
    if i%3==1:
        a.append(l[i]) 
    if i%3==2: # ｓに代入しつつ文字列に置き換え
        s.append(l[i])
for m in range(t):
    for j in range(n[m][0]):
        if j==0:
            x = a[0][0]
        if j>0:
            x =a[m][j] ^ x
    ans = format(x, 'b')
    print(ans[-1])

Submission status: Wrong Answer

Solution code:
t = int(input())
try_arr = []
for i in range(t):
    n = int(input())
    a = input().split()
    s = str(input())
    x = bin(0)
    try_arr.append([n,a,s,x])
for arr in try_arr:
    for i in range(arr[0]):
        if arr[2][i] == '0':
            if arr[3] != bin(0) or bin(int(arr[3], 2) ^ int(arr[1][i])) == bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            else:
                pass
        else:
            if arr[3] == bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            elif bin(int(arr[3], 2) ^ int(arr[1][i])) != bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            else:
                pass
    if arr[3] == bin(0):
        print('0')
    else:
        print('1')

Submission status: Wrong Answer

Solution code:
t = int(input())
l = [list(map(int,input().split())) for _ in range(t*3)]

ans=[]
n = []
a = []
s = []
#n,a,sに代入
for i in range(t*3):
    if i%3==0:
        n.append(l[i]) 
    if i%3==1:
        a.append(l[i]) 
    if i%3==2: # ｓに代入しつつ文字列に置き換え
        s.append(l[i])
for m in range(t):
    for j in range(n[m][0]):
        if j==0:
            x = a[0][0]
        if j>0:
            x =a[m][j] ^ x
    ans = int(format(x, 'b')) % 10
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from functools import reduce

def solve():
    n = int(input())#length of n
    a = list(map(int, input().split()))
    s = list(map(int, input().strip()))
    res = 0
    for i in range(n):
        if s[i] == 1:
            if res == a[i]:
                pass
            else:
                res ^= a[i]
        if s[i] == 0:
            if res == a[i]:
                res ^= a[i]
            else:
                pass

    if res != 0:
        print("1")
    else:
        print("0")

t = int(input())
for i in range(t):
    solve()

Submission status: Wrong Answer

Solution code:
a=input()

print(a)

Submission status: Wrong Answer

Solution code:
t = int(input())
try_arr = []
for i in range(t):
    n = int(input())
    a = input().split()
    s = str(input())
    x = bin(0)
    try_arr.append([n,a,s,x])
for arr in try_arr:
    for i in range(arr[0]):
        if arr[2][i] == '0':
            if arr[3] != bin(0) and bin(int(arr[3], 2) ^ int(arr[1][i])) == bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            else:
                pass
        else:
            if arr[3] == bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            elif bin(int(arr[3], 2) ^ int(arr[1][i])) != bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            else:
                pass
    if arr[3] == bin(0):
        print('0')
    else:
        print('1')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")

import sys,collections,math
sys.setrecursionlimit(1000000)

INF = float("inf")

T = int(sys.stdin.readline())
for _ in range(T):
    N = int(sys.stdin.readline())
    A = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
    S = sys.stdin.readline().rstrip()
    a = []
    b = []
    n_0 = 0
    ab=0
    bb=0
    for i in range(N):
        if S[i] == '0':
            a.append(A[i])
            n_0+=1
            ab = A[i]|ab
        else:
            b.append(A[i])
            bb = A[i]|bb
    #print(S,A)
    if (ab & bb) == bb:
        print('0')
        continue
    S=['1']*(N-n_0)+['0']*n_0
    A=b+a
    #print(S,A)
    def backtrack(i,x):
        if i == N:
            return x==0
        if S[i] == '0':
            if x == 0:
                return True
            if backtrack(i+1,x^int(A[i])) == False and backtrack(i+1,x) == False:
                return False
            else:
                return True
        else:
            if backtrack(i+1,x^int(A[i])) == True and backtrack(i+1,x)==True:
                return True
            else:
            #if backtrack(i+1,x^int(A[i])) == False or backtrack(i+1,x)==False:
                return False

    if backtrack(0,0)==True:
        print("0")
    else:
        print("1")

Submission status: Wrong Answer

Solution code:
import numpy as np
from functools import reduce

def solve():
    n = int(input())#length of n
    a = list(map(int, input().split()))
    s = list(map(int, input().strip()))
    res = 0
    res = res^a[0]
    for i in range(n):
        if s[i] == 1:
            if res == a[i]:
                pass
            else:
                res ^= a[i]
        if s[i] == 0:
            if res == a[i]:
                res ^= a[i]
            else:
                pass

    if res != 0:
        print("1")
    else:
        print("0")

t = int(input())
for i in range(t):
    solve()

Submission status: Wrong Answer

Solution code:
def main():
    def sweep(arr):
        col = max(arr).bit_length()
        row = len(arr)

        rank = 0
        for c in range(col):
            piv = -1
            for r in range(c, row):
                if arr[r] >> c & 1:
                    piv = r
            if piv == -1:
                continue

            arr[piv], arr[rank] = arr[rank], arr[piv]

            for r in range(row):
                if r == rank:
                    continue
                if arr[r] >> c & 1:
                    arr[r] ^= arr[rank]

            rank += 1

        return set(arr)

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

        pre = '-1'
        left = 0
        for i, s in enumerate(S):
            if s != pre and i != 0:
                if s == '0':
                    B1 = sweep(A[left:i])
                    for b1 in B1:
                        for b0 in B0:
                            if b1 & b0:
                                b1 ^= b0
                        if b1:
                            return 1
                else:
                    B0 = B0 | sweep(A[left:i])

                left = i

            pre = s

        if pre == '1':
            B1 = sweep(A[left:])
            for b1 in B1:
                for b0 in B0:
                    if b1 & b0:
                        b1 ^= b0
                if b1:
                    return 1

        return 0

    for _ in [0]*int(input()):
        print(solve())


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
r =[]
T = int(input())

for i in range(T):
    N = int(input())
    A = list(map(int,input().split())) 
    S = list(map(str,input()))
    x = 0
    A_1 = map(lambda x: x % 2, A)
    A_1 = list(A_1)
    
    for i in range(len(S) ):
        
        if S[i] == '0':
            if A_1[i] == x:
                x =0
            else:
                x =x
                

        elif S[i] == '1':
            if not A_1[i] == x:
                x = 1
            else:
                x =x
    r.append(x)
for i in range(T):
    print(r[i])

Submission status: Wrong Answer

Solution code:
t = int(input())
for _ in range(t):
    n = int(input())
    a_li = list(map(int,input().split()))
    s_li = list(input())
    #print(s_li)
    all_li = []
    tmp = []
    now = ''
    for i, (a,s) in enumerate(zip(a_li,s_li)):
        if i == 0:
            now = s
            tmp.append(a)
        else:
            if s == now:
                tmp.append(a)
            else:
                all_li.append([now,tmp])
                now = s
                tmp = [a]
    all_li.append([now,tmp])
    #print(all_li)
    #[['1', [2, 3, 4]], ['0', [5, 6, 7]]]
    x = 0
    for al in all_li:
        kumi = al[0]
        kouho = al[1]
        if kumi == '1':
            for kou in kouho:
                if x == 0:
                    x = x^kou
        else:
            if x != 0:
                while len(kouho)>0:
                    if x == 0:
                        break
                    pp = kouho.pop(0)
                    #print(pp,'pp')
                    tt = x^pp
                    #print(tt,kouho,'tt','kouho')
                    kkk_li = []
                    for kkk in kouho:
                        kkk_li.append(tt^kkk)
                    if 0 in kkk_li:
                        x = 0
                    else:
                        x = tt
    if x == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
t=int(input())
res=list()

def ea(lst):
    flag=1
    while flag==1:
        flag=0
        for i in range(len(lst)):
            for j in range(i+1,len(lst)):
                if  lst[i]^lst[j] < lst[i] and lst[i]^lst[j]!=0:
                    flag=1
                    lst[i]=lst[i]^lst[j]
                if lst[i]^lst[j] < lst[j] and lst[i]^lst[j]!=0:
                    flag=1
                    lst[j]=lst[i]^lst[j]
    return(lst)
        
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=str(input())
    black=list()
    white=list()
    for i in range(n):
        if s[i]=="1":
            black.append(a[i])
        else:
            white.append(a[i])
    black=ea(black)
    white=ea(white)
    for item in black:
        if item in white:
            black.remove(item)
    black.extend(white)
    black=ea(black)
    ans=0
    for item in black:
        if (not item in white):
            f=0
            for i in range(len(white)):
                if item^white[i] in white:
                    f=1
            if f==0:
                ans=1
    res.append(ans)
    
for i in res:
    print(i)

Submission status: Wrong Answer

Solution code:
T = int(input())
ans = []
for _ in range(T):
    x = 0
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    for i in range(N):
        if S[i] == "1":
            if x^A[i] != 0 and x^A[i] not in A:
                x = x ^ A[i]
        elif S[i]=="0":
            if x^A[i]==0 and x^A[i] in A:
                x = x ^ A[i]
    ans+= [0] if x==0 else [1]
for x in ans:
    print(x)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")

import sys,collections,math
sys.setrecursionlimit(1000000)

INF = float("inf")

T = int(sys.stdin.readline())
for _ in range(T):
    N = int(sys.stdin.readline())
    A = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
    S = sys.stdin.readline().rstrip()
    a = []
    b = []
    n_0 = 0
    ab=0
    bb=0
    for i in range(N):
        if S[i] == '0':
            a.append(A[i])
            n_0+=1
            ab = A[i]|ab
        else:
            b.append(A[i])
            bb = A[i]|bb
    #print(S,A)
    if bb & ab:
        print('0')
        continue
    S=['1']*(N-n_0)+['0']*n_0
    A=b+a
    #print(S,A)
    def backtrack(i,x):
        if i == N:
            return x==0
        if S[i] == '0':
            if x == 0:
                return True
            if backtrack(i+1,x^int(A[i])) == False and backtrack(i+1,x) == False:
                return False
            else:
                return True
        else:
            if backtrack(i+1,x^int(A[i])) == True and backtrack(i+1,x)==True:
                return True
            else:
            #if backtrack(i+1,x^int(A[i])) == False or backtrack(i+1,x)==False:
                return False

    if backtrack(0,0)==True:
        print("0")
    else:
        print("1")

Submission status: Wrong Answer

Solution code:
t = int(input())
for i in range(t):
    x = 0
    n = int(input())
    a = list(map(int, input().split()))
    s = input()
    for i in range(n):
        a2 = bin(a[i])
        x2 = bin(x)
        t = a[i] ^ x
        t2 = bin(t)
        numx1 = x2.count("1")
        numt1 = t2.count("1")
        if s[i] == "0":
            if numt1 < numx1:
                x = t
        else:
            if numt1 > numx1:
                x = t
    if x == 0 and s[n-1] != 1:
        print("0")
    else:
        print("1")

Submission status: Wrong Answer

Solution code:
t=int(input())
res=list()

def ea(lst):
    flag=1
    while flag==1:
        flag=0
        for i in range(len(lst)):
            for j in range(i+1,len(lst)):
                if  lst[i]^lst[j] < lst[i] and lst[i]^lst[j]!=0:
                    flag=1
                    lst[i]=lst[i]^lst[j]
                if lst[i]^lst[j] < lst[j] and lst[i]^lst[j]!=0:
                    flag=1
                    lst[j]=lst[i]^lst[j]
    return(lst)
        
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=str(input())
    black=list()
    white=list()
    for i in range(n):
        if s[i]=="1":
            black.append(a[i])
        else:
            white.append(a[i])
    black=ea(black)
    white=ea(white)
    for item in black:
        if item in white:
            black.remove(item)
    black.extend(white)
    black=ea(black)
    ans=0
    for item in black:
        if (not item in white):
            f=0
            for i in range(len(white)):
                if item^white[i] in white:
                    f=1
            if f==1:
                ans=1
    res.append(ans)
    
for i in res:
    print(i)

Submission status: Wrong Answer

Solution code:
K=60

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

    M=[]
    C=[]
    for i in range(N):
        if S[i]=="0":
            M.append(A[i])
        else:
            C.append(A[i])

    L=len(M)
    E=M+C


#E[j]>>i:i行j列

    J=0
    for x in range(min(K,L)):
        i=J
        if (E[i]>>i)%2==0:
                flag=1
                for I in range(i+1,min(K,L)):
                    if i!=I and (E[i]>>I)%2 and flag:
                        flag=0
                        for j in range(N):
                            p=(E[j]>>i)%2
                            q=(E[j]>>I)%2

                            if p!=q:
                                E[j]=E[j]^(1<<i)^(1<<I)
                        

        if (E[i]>>i)%2:
            J+=1
            F=[]
            for j in range(N):
                F.append((E[j]>>i)%2)

            for I in range(min(K,L)):
                if (i!=I) and ((E[i]>>I)%2):
                    for j in range(N):
                        E[j]^=(F[j]<<I)
                        
    H=0
    for i in range(K):
        f=0
        for j in range(L):
            f=max(f,(E[j]>>i)%2)

        if f==0:
            for j in range(L,N):
                if (E[j]>>i)%2:
                    H=1

    print(H)

Submission status: Wrong Answer

Solution code:
T = int(input())
ans = []
x = 0
for i in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    S = str(input())
    for j in range(N):
        x = x ^ A[j]
    if x != 0:
        x = 1
    ans.append(x)
    x = 0
for k in range(T):
    print(ans[k])

Submission status: Wrong Answer

Solution code:
T = int(input())
ans = []
for _ in range(T):
    x = 0
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    for i in range(N):
        if S[i] == "1":
            if x^A[i] != 0:
                x = x ^ A[i]
        elif S[i]=="0":
            if x^A[i]==0:
                x = x ^ A[i]
    ans+= [0] if x==0 else [1]
for x in ans:
    print(x)

Submission status: Wrong Answer

Solution code:
import numpy as np
t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    s = input()
    lsa = np.zeros((200,60))
    if s[-1] == "1":
        print(1)
        continue
    for i in range(n-1,-1,-1):
        b = format(a[i], '060b')
        if s[i] == "0":
            for j in range(60):
                lsa[i][j] = int(b[j])
            ra = np.linalg.matrix_rank(lsa)
        else:
            for j in range(60):
                lsa[i][j] = int(b[j])
            rb = np.linalg.matrix_rank(lsa)
            if rb != ra:
                print(1)
                break
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
r =[]
T = int(input())

for i in range(T):
    N = int(input())
    A = list(map(int,input().split())) 
    S = list(map(str,input()))
    x = 0
    A_1 = map(lambda x: x % 2, A)
    A_1 = list(A_1)
    
    for i in range(len(S) ):
        
        if S[i] == '0':
            if A_1[i] == x:
                x =0
                

        elif S[i] == '1':
            if not A_1[i] == x:
                x = 1
    r.append(x)
for i in range(T):
    print(r[i])

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        A = [int(i) for i in input().split()]
        S = list(input())
        ans = 0
        for i in range(N):
            if S[i] == '0':   
                if ans ^ A[i] == 0:
                    ans = 0
                else:
                    flag = False
                    a = ans ^ A[i]
                    for j in range(i+1, N):
                        if S[j] == '0' and a ^ A[j] == 0:
                            flag = True
                            break
                    if flag:
                        ans = ans ^ A[i]
            else:
                flag = False
                a = ans ^ A[i]
                for j in range(i+1, N):
                    if S[j] == '0' and a ^ A[j] == 0:
                        flag = True
                        break
                if not flag:
                    ans = ans ^ A[i]
        if ans == 0:
            print('0')
        else:
            print('1')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()

        # 人１がビットを最後に立てた後に０にできるなら０にならない
        L = max(A).bit_length()
        if S[-1] == '1':
            print(1)
        else:
            cur = 0
            ss = [[0, 0] for i in range(N+1)]
            for i in range(N-1, -1, -1):
                if S[i] == '0':
                    ss[i][0] = ss[i+1][0] | A[i]
                    ss[i][1] = ss[i+1][1]
                else:
                    ss[i][1] = ss[i+1][1] | A[i]
                    ss[i][0] = ss[i+1][0]

            for i in range(N):
                k = int(S[i])
                tmp = ss[i+1]

                for j in range(L):
                    if k == 1:
                        if (cur >> j) % 2 == 0 and (A[i] >> j) % 2 and ((tmp[0] >> j) % 2 == 0):
                            cur ^= A[i]
                            break
                    else:
                        if (cur >> j) % 2 and (A[i] >> j) % 2 and ((tmp[1] >> j) % 2 == 0):
                            cur ^= A[i]
                            break

            if cur == 0:
                print(0)
            else:
                print(1)


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from functools import reduce
from operator import xor


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    S = input().strip()
    return N, A, S


def solve(N, A, S):
    if S[-1] == "1":
        return 1
    P = [0, 0]
    for s, a in zip(S, A):
        if s == "0":
            P[0] |= int(a)
        elif s == "1":
            P[1] |= int(a)
        else:
            raise ValueError()
    while P[0] > 0 or P[1] > 0:
        if P[1] & 1 == 1 and P[0] & 1 == 0:
            return 1
        P[0] >>= 1
        P[1] >>= 1
    return 0


if __name__ == '__main__':
    T = int(input().strip())
    for i in range(T):
        inputs = read()
        outputs = solve(*inputs)
        if outputs is not None:
            print("{}".format(outputs))

Submission status: Wrong Answer

Solution code:
t = int(input())

n = 0
a = []
s = ''

def solve(x, i):
  global n, a, s
  p = s[i]
  
  if i == (n-1):
    # 最後の操作
    if p == '0':
      if x == 0 or x^a[i] == 0:
        return '0'
      else:
        return '1'
    else:
      if x != 0 or x^a[i] != 0:
        return '1'
      else:
        return '0'
  else:
    if p == '0':
      if x^a[i] == 0:
        return solve(x^a[i], i+1)
      else:
        return solve(x, i+1)
    else:
      if x^a[i] != 0:
        return solve(x^a[i], i+1)
      else:
        return solve(x, i+1)
  

for i in range(t):
  n = int(input())
  a = list(map(int, input().split()))
  s = input()
  
  #print('T : ', i)
  #print(n)
  #print(a)
  #print(s)
  
  #print('solve')
  print(solve(0,0))

Submission status: Wrong Answer

Solution code:
T = int(input())
ans = []
for _ in range(T):
    x = 0
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    for i in range(N):
        if S[i] == "1":
            if x^A[i] != 0:
                x = x ^ A[i]
        elif S[i]=="0":
            if x!=0:
                x = x ^ A[i]
    ans+= [0] if x==0 else [1]
for x in ans:
    print(x)

Submission status: Wrong Answer

Solution code:

def test(n,a,s):
    x = 0
    player = 0
    for iround in range(n):
        player = int(s[iround])
        ai = a[iround]%2
        if player == 0:
            if x%2 == 1 and ai == 1:
                x = 0           
        else:
            if x%2 == 0 and ai == 1:
                x = 1
    print(x)

t = int(input())
n = []
a = []
s = []
for i in range(t):
    n.append(int(input()))
    a.append(list(map(int,input().split())))
    s.append(input())


for i in range(t):
    test(n[i],a[i],s[i])

Submission status: Wrong Answer

Solution code:
t = int(input())
ans = []
for j in range(t):
    n = int(input())
    a = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
    str = input()
    s = list(str)

    x = 0

    for i in range(n-1):
        x = x^a[i]

    if s[-1] == '0':
        if not x == 0:
            x = x^a[-1]
    else:
        if x == 0:
            x = x^a[-1]
    if x == 0:
        ans.append('0')
    else:
        ans.append('1')

for i in ans:
    print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K=60

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

    M=[]
    C=[]
    for i in range(N):
        if S[i]=="0":
            M.append(A[i])
        else:
            C.append(A[i])

    L=len(M)
    E=M+C


#E[j]>>i:i行j列
    
    for i in range(min(K,L)):
        if (E[i]>>i)%2==0:
                flag=1
                for I in range(i+1,min(K,L)):
                    if i!=I and (E[i]>>I)%2 and flag:
                        flag=0
                        for j in range(N):
                            p=(E[j]>>i)%2
                            q=(E[j]>>I)%2

                            if p!=q:
                                E[j]=E[j]^(1<<i)^(1<<I)
                        

        if (E[i]>>i)%2:
            F=[]
            for j in range(N):
                F.append((E[j]>>i)%2)

            for I in range(min(K,L)):
                if (i!=I) and ((E[i]>>I)%2):
                    for j in range(N):
                        E[j]^=(F[j]<<I)                   

    H=1
    for i in range(K):
        f=0
        for j in range(L):
            f=max(f,(E[j]>>i)%2)

        if f==0:
            for j in range(L,N):
                if (E[j]>>i)%2:
                    H=0        

    print(1-H)