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):
  x = 0
  N = int(input())
  A = list(map(int, input().split()))
  S = list(input())

  for i in range(N):
#    print(S[i], A[i], x)
    if S[i] == '0':
      if x == 0:
        continue
      else:
        x = x ^ A[i]
    else:
      xx = x ^ A[i]
      if xx != 0:
        x = xx
      else:
        continue        
#    print(x)
  if x == 0:
    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()
    if s[-1]=="1":
        print(1)
        continue
    a0,a1=[],[]
    f=False
    for j in range(n-1,-1,-1):
        if s[j]=="0":
            if not f:
                a0.append(a[j])
        else:
            f=True
            a1.append(a[j])
    l0,l1=len(a0),len(a1)
    for j in range(l0):
        for k in range(l0):
            if j!=k:
                a0[k]=min(a0[k],a0[j]^a0[k])
    for j in range(l1):
        for k in range(l1):
            if j!=k:
                a1[k]=min(a1[k],a1[j]^a1[k])
    a0+=[0]
    a1+=[0]
    a0=list(set(a0))
    a1=list(set(a1))
    a0.sort()
    a1.sort()
    l0,l1=len(a0),len(a1)
    for i in range(l1):
        if a1[i] not in a0:
            print(1)
            break
    else:
        print(0)

Submission status: Wrong Answer

Solution code:

T = int(input()) #Tを取得し、intに値を入れる
#print(T) #出力：T
#T取得完了

for i in range(T):
  N = int(input())
  #print('N',i,'=',N)
  A = list(map(int, input().split())) #i_1 i_2を取得し、iに値を入れる
  #print('A[',i,']=',A[0]) #出力：A_1
  #print('A[',i,']=',A[1]) #出力：A_2
  S=list(map(int,input()))
  #print('S[',i,']=',S[0]) #出力：N_1
  #print('S[',i,']=',S[1]) #出力：N_2
  #ここまでで1回分の文字が取得できた
  x = 0
  for j in range(N):
    if ((S[j]==0 and x == 0)):
      break
    elif(S[j]==0): #player0の行動
      if(x^A[j]==0):
        x=0           #もしその場でx^A[j]が0にできるならする
      elif(j < N-1):           #できなくとも、その後のAのどれかと同じならする
        count = j+1
        while (S[count]==0):
          if(x^A[j] == A[count]):
            x = x^A[j]
            break
          else:
            count +=1
      else:
        break
    else:
      if(A[j] > x):
        x= x^A[j]
      else:
        break
  if(x==0):
    print('0')
  else:
    print('1')

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

    L0 = []
    L1 = []
    for i in range(N):
        if S[i] == "1":
            L1.append(A[i])
        else:
            L0.append(A[i])

    L00 = L0[:]
    for i in range(len(L0)):
        for j in range(len(L0)):
            t = L0[i] ^ L0[j]
            # if t < L0[i] and t < L0[j]:
            #     L00.append(t)
            L00.append(t)

    L0 = list(set(L00))
    L0.sort(reverse=True)
    f = 1
    for l1 in L1:
        t = l1
        for l0 in L0:
            t = min(t, t ^ l0)
        if t != 0:
            f = 0
            break
    if f:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
from operator import xor
from functools import reduce
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    T = int(input())
    for _ in [0] * T:
        N = int(input())
        A = list(map(int, input().split()))
        S = input()

        n = reduce(xor, A)
        x = 0
        for i, s in enumerate(S):
            if s == '0':
                if not x or x ^ A[i] == 0:
                    x ^= A[i]
                    n ^= x
            else:
                if x or x ^ A[i] != 0:
                    x ^= A[i]
                    n ^= x
        print(x % 2)


main()

Submission status: Wrong Answer

Solution code:
def main(n,a,s):
  #orders=0
  x=0
  x1=0
  x2=0
  for orders in range(n):
    man = s[orders]
    amn = a[orders]
    if man=="0":
      if x ^ amn == 0:
        x=0
      if x1 ^ amn == 0 and x1 >0:
        x1=0
      if x2 ^ amn == 0:
        x2=0
      elif x2> 0:
        x2 = x2 ^ amn
    else:
      notzero = x ^ amn
      if  notzero >0 :
        x=notzero
      notzero = x1 ^ amn
      if  x1==0 and notzero >0 :
        x1=notzero
      notzero = x2 ^ amn
      if  notzero >0:
        x2=notzero
  if (x1==0 or x2==0) and x==0:
    print(0)
  else:
    print(1)
    
t=int(input())
for i in range(t):
  n=int(input())
  a=list(map(int,input().split()))
  s=input()
  main(n,a,s)

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    S=str(input())
    s=[]
    for j in range(n):
        a[j]=a[j]&1
        s.append(int(S[j]))
    if not 1 in a:
        print(0)
    else:
        for j in range(n):
            if a[-1-j]==1:
                print(s[-1-j])
                break

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:
                if ans == 0:
                    ans = ans ^ A[i]
                else:
                    flag = False
                    for j in range(i+1, N):
                        if S[j] == '0' and ans ^ A[j] == 0:
                            flag = True
                            break
                    if flag:
                        ans = ans ^ A[i]
        if ans == 0:
            print('0')
        else:
            print('1')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

T = int(input())
test = []
for _ in range(T):
    N = int(input())
    als = inpl()
    s = str(input())
    test.append((s,als))

def part(v,ls):#lsの値でvを0にできるか
    result = []
    def dfs(r,sum):
        if r==len(ls):
            if sum ^ v == 0:
                return True
            else:
                return False
        if dfs(r+1,sum):
            return True
        if dfs(r+1,sum^ls[r]):
            result.append(ls[r])
            return True

        return False
    res = dfs(0,0)
    return res,result
for item in test:
    ss = list(item[0])
    als = []
    bls = []
    for kk,num in enumerate(ss):
        if num == '0':
            als.append(item[1][kk])
        else:
            bls.append(item[1][kk])
    bbb = sum(bls)
    f,re = part(bbb,als)
    if f:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
from operator import xor
from functools import reduce
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    T = int(input())
    for _ in [0] * T:
        N = int(input())
        A = list(map(int, input().split()))
        S = input()

        n = reduce(xor, A)
        x = 0
        for i, s in enumerate(S):
            if s == '0':
                if x ^ A[i] == 0:
                    x ^= A[i]
                    n ^= x
            else:
                if x ^ A[i] != 0:
                    x ^= A[i]
                    n ^= x
        print(x % 2)


main()

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):
                pass
            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
        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:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    T = iRaw()
    for t in range(T):
        N = iRaw()
        As = isRaw()
        S = sRaw()
        ASs = zip(As,S)

        if S[-1]=="1":
            print(1)
            continue
        failed = 0
        def isAble(aFrom,a_val):
            availeA = [As[idx] for idx in range(aFrom,N) if S[idx]=='0']
            aSet = set(availeA)
            if a_val in aSet:
                return 0
            b1s = [0]*18
            for a in aSet:
                for bidx in range(18):
                    b_val = 1 << bidx
                    if a & b_val:
                        b1s[bidx]+=1
            for a in aSet:
                failed = 0
                axora =  a ^ a_val
                for bidx in range(18):
                    b_val = 1 << bidx
                    if (axora & b_val)!=0 and b1s[bidx]<2:
                        failed= 1
                        break
                if failed==0:
                    return 0
            return 1

        for aisx, a_s in enumerate(ASs):
            a,s = a_s
            if s == '1':
                failed = isAble(aisx+1,a)
                if failed:
                    break

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


main()

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(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
            

print(x)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
t = int(input())
def judge(mat,x,pivot):
  b = x.bit_length()
  for i in range(b)[::-1]:
    if x&1<<i:
      if i not in pivot:
        return False
      for j in range(len(mat)):
        if mat[j]&1<<i:
          x ^= mat[j]
          break
  return True
def add(mat,x,pivot):
  b = x.bit_length()
  for i in range(b)[::-1]:
    if x&1<<i:
      if i in pivot:
        for j in range(len(mat)):
          if mat[j]&1<<i:
            x ^= mat[j]
            break
      else:
        pivot.add(i)
        for j in range(len(mat)):
          if mat[j] > x and mat[j]&1<<i:
            mat[j] ^= x
          elif mat[j] < x:
            mat.insert(j,x)
            for k in range(i)[::-1]:
              if mat[j]&1<<k and k in pivot:
                for l in range(j+1,len(mat)):
                  if mat[l]&1<<k:
                    mat[j] ^= mat[l]
            break
        else:
          mat.append(x)
        break
for _ in range(t):
  n = int(input())
  a = list(map(int,input().split()))
  s = input().rstrip()
  pivot = set()
  mat = []
  for i in range(n)[::-1]:
    x = a[i]
    if s[i] == "0":
      if judge(mat,x,pivot):
        continue
      else:
        add(mat,x,pivot)
    else:
      if judge(mat,x,pivot):
        continue
      else:
        print(1)
        break
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    S=str(input())
    s=[]
    for j in range(n):
        a[j]=a[j]&1
        s.append(int(S[j]))
    t=s[0]
    q=[a[0]]
    for j in range(1,n):
        if s[j]==s[j-1]:
            q[-1]=q[-1]|a[j]
            #1を含むか
        else:
            q.append(a[j])
            t=t^1
            #数字の逆転
    if not 1 in q:
        print(0)
    else:
        t=t^1
        Q=len(q)
        for j in range(Q):
            t=t^1
            if q[-1-j]==1:
                print(t)
                break

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:
            ans=1
    res.append(ans)
    
for i in res:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
t = int(input())
def judge(mat,x,pivot):
  b = x.bit_length()
  for i in range(b)[::-1]:
    if x&1<<i:
      if i not in pivot:
        return False
      for j in range(len(mat)):
        if mat[j]&1<<i:
          x ^= mat[j]
          break
  return True
def add(mat,x,pivot):
  b = x.bit_length()
  for i in range(b)[::-1]:
    if x&1<<i:
      if i in pivot:
        for j in range(len(mat)):
          if mat[j]&1<<i:
            x ^= mat[j]
            break
      else:
        pivot.add(i)
        for j in range(len(mat)):
          if mat[j] > x and mat[j]&1<<i:
            mat[j] ^= x
          elif mat[j] < x:
            mat.insert(j,x)
            for k in range(i)[::-1]:
              if mat[j]&1<<k and k in pivot:
                for l in range(j+1,len(mat)):
                  if mat[l]&1<<k:
                    mat[j] ^= mat[l]
            break
        else:
          mat.append(x)
        break
for _ in range(t):
  n = int(input())
  a = list(map(int,input().split()))
  s = input().rstrip()
  pivot = set()
  mat = []
  for i in range(n)[::-1]:
    x = a[i]
    if s[i] == "0":
      if judge(mat,x,pivot):
        continue
      else:
        add(mat,x,pivot)
        print(mat)
    else:
      if judge(mat,x,pivot):
        continue
      else:
        print(1)
        break
  else:
    print(0)

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:
                if ans == 0:
                    ans = ans ^ A[i]
                else:
                    flag = True
                    a = ans ^ A[i]
                    for j in range(i+1, N):
                        if S[j] == '0' and a ^ A[j] == 0:
                            flag = False
                            break
                    if flag:
                        ans = ans ^ A[i]
        if ans == 0:
            print('0')
        else:
            print('1')


if __name__ == '__main__':
    main()

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(min(K,L)):
        if (E[i]>>i)%2==0:
            for j in range(L,N):
                if (E[j]>>i)%2==1:
                    H=0

    print(1-H)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def solv(N, A, S):
        x = 0
        for i, a in enumerate(A):
            c = S[i]
            bx = list(reversed(format(x, "b")))
            ba = list(reversed(format(a, "b")))
#            print(c, bx, ba)
            if c == "0":
                if x == 0:
                    continue
                else:
                    tmp = ""
                    for j in range(min(len(bx), len(ba))):
                        if bx[j] == "1" and ba[j] == "0":
                            tmp = "1"
                        else:
                            tmp = "0"
                        bx[j] = tmp
            else:
                tmp = "0"
                if (len(ba) > len(bx)):
                    for j in range(len(bx), len(ba)):
                        bx.append(ba[j])
                for j in range(min(len(bx), len(ba))):
                    if bx[j] == "0" and ba[j] == "0":
                        tmp = "0"
                    else:
                        tmp = "1"
                    bx[j] = tmp
            ans = 0
#            print(bx)
            for b in reversed(bx):
                ans += int(b)
                ans *= 2
            ans //= 2
            x = ans
#            print(ans, bin(x))
#        print("ANS--")
        if x == 0:
            print(0)
        else:
            print(1)

def main():
    T = int(input())
    for t in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input().strip()
        solv(N, A, S)



if __name__ == '__main__':
    main()

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:]
        s='0'*(60-len(s))+s
        if S[i]:
            s1=set([d[i] for i in range(60) if s[i]=='1' and d[i]])
            s2=set([d[i] for i in range(60) if s[i]=='0' and d[i]])
            if len(s1)==0 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:
def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

def select(x2, A, S):
  num = len(bin(x2)) -2
  cand = []
  for i in range(num):
    if x2 >> i & 1:
      cand.append(i)
  cand_a = []
  for i, s in enumerate(S):
    if s == 0:
      a = A[i]
      num_a = len(bin(a)) -2
      for j in range(num_a):
        if a >> j & 1:
          cand_a.append(j)
  cand_a = set(cand_a)
  uni_cnt = 0
  for c in cand:
    if c not in cand_a:
      return True
  return False         
      
def solve(N, A, S):
  x = 0
  x2 = 0
  for i in range(N):
    x2 = int(bin(x ^ A[i]),2)
    #print("x2", x2, popcount(x2))
    #print("x", x, popcount(x))
    if S[i] == 1:
      if popcount(x2) >= popcount(x):
        x = x2
      #else:
      #  if select(x2, A, S):
      #    x = x2
    else:
      if popcount(x2) < popcount(x):
        x = x2
  if x == 0:
    print(0)
  else:
    print(1)

T = int(input())
for _ in range(T):
  N = int(input())
  A = [int(i) for i in input().split()]
  S = [int(i) for i in input()]
  solve(N, A, S)

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):
                pass
            elif bin(int(arr[3], 2) ^ int(arr[1][i])) == bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            else:
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
        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())
for t in range(T):
  x = 0
  N = int(input())
  A = list(map(int, input().split()))
  S = list(input())

  for i in range(N):
#    print(S[i], A[i], x)
    if S[i] == '0':
      if x == 0:
        continue
      else:
        x = x ^ A[i]
    else:
      if x != 0:
        continue
      else:
        x = x ^ A[i]
#    print(x)
  if x == 0:
    print(0)
  else:
    print(1)

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)

x = 0
for i in range(T):
    for n in range(N[i]):
        # print(x)
        player = S[i][n]
        result_calc = culculate(x, A[i][n])
        if(player == "0"):
            # if(x != 0):
            if(result_calc == 0):
                x = result_calc 
        if(player == "1"):
            # if(x == 0):
            if(result_calc != 0):
                x = result_calc
    print("0" if x == 0 else "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)
    #black.extend(white)
    black=ea(black)
    ans=0
    for item in black:
        if not item in white:
            ans=1
    res.append(ans)
    
for i in res:
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
def main(i):
    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)
    if x == 0:
        print(0)
    else:
        print(1)

for i in range(N):
    main(i)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

    L0 = []
    L1 = []
    for i in range(N):
        if S[i] == "1":
            L1.append(A[i])
        else:
            L0.append(A[i])

    L00 = L0[:]
    for i in range(len(L0)):
        for j in range(len(L0)):
            t = L0[i] ^ L0[j]
            if t < L0[i] and t < L0[j]:
                L00.append(t)

    L0 = list(set(L00))
    L0.sort(reverse=True)
    f = 1
    for l1 in L1:
        t = l1
        for l0 in L0:
            t = min(t, t ^ l0)
            l10 = t ^ l0
            if l10 <= t:
                t = l10
        if t != 0:
            f = 0
            break
    if f:
        print(0)
    else:
        print(1)

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)

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

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)
                    tt = x^pp
                    if tt in kouho:
                        x = 0
                    else:
                        x = tt
    if x == 0:
        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=list(input())
    x=0
    for j in range(n):
        if s[j]=="1":
            if x^a[j]>x/a[j]:
                x=x^a[j]
        else:
            if x^a[j]<x/a[j]:
                x=x^a[j]
    if x==0:
        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()
    if s[-1]=="1":
        print(1)
        continue
    a0,a1=[],[]
    for j in range(n):
        if s[j]=="0":
            a0.append(a[j])
        else:
            a1.append(a[j])
    a0.sort(reverse=True)
    a1.sort(reverse=True)
    l0,l1=len(a0),len(a1)
    for j in range(l0):
        for k in range(l0):
            if j!=k:
                a0[k]=min(a0[k],a0[j]^a0[k])
    for j in range(l1):
        for k in range(l1):
            if j!=k:
                a1[k]=min(a1[k],a1[j]^a1[k])
    a0+=[0]
    a1+=[0]
    a0=list(set(a0))
    a1=list(set(a1))
    a0.sort()
    a1.sort()
    l0,l1=len(a0),len(a1)
    for i in range(l1):
        if a1[i] not in a0:
            print(1)
            break
    else:
        print(0)