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:
num = int(input())
x = 0
for i in range(num):
  ran = int(input())
  su = map(int,input().split())
  man = list(map(int,(input())))
  for count,k in enumerate(su):
    ans = bin(x ^ k)
    #もしlistの中身
    if man[count] == 0 and x == 0 and int(ans,0) != 0:
      pass
    elif man[count] == 1 and int(ans,0) == 0:
      pass
    else:
      x = int(ans,0)
  if x == 0:
    print(0)
  else:
    print(1)
  x = 0

Submission status: Wrong Answer

Solution code:
t = input()
x = 0

for i in range(int(t)):
    N = map(int, input())
    A = list(input().split())
    S = map(int, input())
    for z in A:
        bitwise = bin(int(x) ^ int(z))[2:]
        x = int(bitwise, 2)
        if (x == 0):
            break

    if x == 0:
        print(0)
    else:
        print(1)
    x = 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=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()
    a1.sort()
    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:
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 partplus(v,ls):
    dp =[[False]*(v+1) for _ in range(lsn(ls))]#i番目までみたときjが可能かどうか
    ddp = [0]*len(ls)
    for i in range(lsn(ls)):
        for j in range(V+1):
            item = ls[i]
            dp[i][j] = dp[i-1][j] or dp[i-1][max(0,j-item)]
            if dp[i][j] == True:"""

def part(v,ls):
    result = []
    def dfs(r,sum):
        if r==len(ls):
            if sum == v:
                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])
    for item2 in bls:
        f,re = part(item2,als)
        if f:
            for item3 in re:
                als.remove(item3)
        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=list(input())
    x=0
    for j in range(n):
        if s[j]=="1":
            if x^a[j]>x/3:
                x=x^a[j]
        else:
            if x^a[j]<x/3:
                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 not "0" in s:
        print(1)
    elif not "1" in s:
        print(0)
    else:
        fir=[]
        sec=[]
        for j in range(n):
            if s[j]=="1":
                fir.append(a[j])
            else:
                sec.append(a[j])
        fir.sort()
        sec.sort()
        first=0
        for x in fir:
            first^=x
        if sec[0]<=first<=sec[-1]:
            print(0)
        else:
            print(1)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    for t in range(int(input())):
        N = int(input())
        A = list(map(int, input().split()))
        S = input().rstrip('\n')
        A.reverse()
        S = S[::-1]

        A0 = [0] * 60
        A1 = [0] * 60
        zero = 0
        one = 0
        for i, a in enumerate(A):
            if S[i] == "0":
                for j in range(60):
                    A0[j] ^= ((a >> j & 1) << zero)
                zero += 1
            else:
                for j in range(60):
                    A1[j] ^= ((a >> j & 1) << one)
                one += 1

        B = [0] * 60
        for i in range(60):
            B[i] = A0[i] + (A1[i] << zero)

        rnk = 0
        for i in range(zero):
            #print(B)
            for j in range(rnk, 60):
                if B[j] >> i & 1:
                    B[j], B[rnk] = B[rnk], B[j]
                    b = B[rnk]
                    #print(b)
                    for jj in range(60):
                        if jj == rnk:
                            continue
                        if B[jj] >> i & 1:
                            B[jj] ^= b
                    rnk += 1
                    break

        print(0)
        continue

        cnt0 = 0
        cnt1 = zero
        r = -1
        win = 0
        for s in S:
            if s == "0":
                if B[r+1] >> cnt0 & 1:
                    r += 1
                cnt0 += 1
                if r == 60:
                    break
            else:
                rr = -1
                for j in range(60):
                    if B[j] >> cnt1 & 1:
                        rr = j
                if rr > r:
                    win = 1
                    break
                cnt1 += 1
        print(win)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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"
                for j in range(len(bx)):
                    bx[j] = bx[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 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/2:
                x=x^a[j]
        else:
            if x^a[j]<x/2:
                x=x^a[j]
    if x==0:
        print(0)
    else:
        print(1)

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 x==0 or x1==0 or x2==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=input()
    if not "0" in s:
        print(1)
    elif not "1" in s:
        print(0)
    else:
        fir=[]
        sec=[]
        for j in range(n):
            if s[j]=="1":
                fir.append(a[j])
            else:
                sec.append(a[j])
        fir.sort()
        sec.sort()
        first=0
        second=0
        for x in fir:
            first^=x
        for y in sec:
            second^=y

        if first<second:
            print(1)
        else:
            print(0)

Submission status: Wrong Answer

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

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]!=0:
                x=x^a[j]
        else:
            if x^a[j]==0:
                x=x^a[j]
    if x==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()))[::-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='2'*(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:
class TestCase:
    def __init__(self):
        self.N = None
        self.A = None
        self.S = None
        self.x = 0

TestCases = []
T = int(input())
for i in range(T):
    TestCases.append(TestCase())
for i in range(T):
    TestCases[i].N = int(input())
    TestCases[i].A = list(input().split(" "))
    TestCases[i].S = input()
for t in range(T):
    for i in range(TestCases[t].N):
        if TestCases[t].S[i] == "0":
            if TestCases[t].x != 0:
                TestCases[t].x = TestCases[t].x ^ int(TestCases[t].A[i])
        elif TestCases[t].S[i] == "1":
            if TestCases[t].x == 0:
                TestCases[t].x = TestCases[t].x ^ int(TestCases[t].A[i])
    if TestCases[t].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]>=1:
                x=x^a[j]
        else:
            if x^a[j]<x:
                x=x^a[j]
    if x==0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
num = int(input())
x = 0
for i in range(num):
  ran = int(input())
  su = map(int,input().split())
  man = list(map(int,(input())))
  for count,k in enumerate(su):
    ans = bin(x ^ k)
    #もしlistの中身
    if man[count] == 0 and x == 0 and int(ans,0) != 0:
      x = int(ans,0)
    elif man[count] == 1 and int(ans,0) == 0:
      x = int(ans,0)
    else:
      x = int(ans,0)
      print(x)

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
            #数字の逆転
    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())

N = []
A = []
S = []

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

answer = []

for N1,A1,S1 in zip(N,A,S):
    x = 0
    for i in range(N1):
        if int(S1[i]) == 0:
            if x != 0 or int(int(x) ^ int(A1[i])) == 0:
                x = int(int(x) ^ int(A1[i]))
            elif 2 < N1 - i:
                if int(int(int(x) ^ int(A1[i])) ^ int(A1[i + 1])) ^ int(A1[i + 2]) == 0:
                    x = int(int(x) ^ int(A1[i]))
                else:
                    pass
            else:
                pass
        if int(S1[i]) == 1:
            if x == 0 or int(int(x) ^ int(A1[i])) != 0:
                x = int(int(x) ^ int(A1[i]))
            elif 2 < N1 - i:
                if int(int(int(x) ^ int(A1[i])) ^ int(A1[i + 1])) ^ int(A1[i + 2]) != 0:
                    x = int(int(x) ^ int(A1[i]))
                else:
                    pass
            else:
                pass
    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])
    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:
import random
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 N1,A1,S1 in zip(N,A,S):
    print(random.randrange(2))

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]!=0:
                x=x^a[j]
        else:
            if x^a[j]<x:
                x=x^a[j]
    if x==0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
import math


def helper(arr):
    res = set()
    for bit_array in range(1 << len(arr)):
        bit = bit_array
        s = 0
        while bit:
            idx = int(math.log2(bit & ~(bit - 1)))
            s ^= arr[idx]
            bit &= bit - 1
        res.add(s)
    return res


t = int(input())

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

    d = {'0': set(), '1': set()}
    for i in range(n):
        d[s[i]].add(a[i])
    
    if len(d['0']) != len(d['1']):
      print(1)
      continue

    p = helper(list(d['0'])) == helper(list(d['1']))
    print(1 - p)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
from operator import itemgetter


def sweep(l):
    result = []
    s = set(l)
    while s:
        a = max(s)
        b = 1 << (a.bit_length() - 1)
        s = {t ^ a if t >= b else t for t in s}
        s.discard(0)
        result.append([a, 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 = grp[1:]

    pre = []

    for l1, l0 in zip(grp[0::2], grp[1::2]):
        l1.extend(pre)
        s0 = sweep(l0)

        for a, b in s0:
            for i in range(len(l1)):
                if l1[i] & b:
                    l1[i] ^= a
        # print(l0, s0, l1)

        s1 = set(l1)
        s1.discard(0)
        pre = list(s1)

    if pre:
        buf.append(1)
    else:
        buf.append(0)

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

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:
        print("0")
    else:
        print("1")

Submission status: Wrong Answer

Solution code:
t=int(input())
for _ in range(t):
    ans=-1
    n=int(input())
    a=[int(j)for j in input().split()]
    s=input()
    if s[-1]=="1":
        ans=1
        print(ans)
    if ans==-1:
        lz=set()
        ll=set()
        lo=set()
        for i,j in zip(a,s):
            if j=="1":
                lo.add(i)
                lz=set()
            else:
                if i in lo:
                    lo.remove(i)
                lz.add(i)
        cz=[0]*60
        for i in lz:
            for j in range(60):
                cz[j]+=i>>j&1
        co=[0]*60
        for i in lo:
            for j in range(60):
                co[j]+=i>>j&1
        for i,j in zip(cz,co):
            if i<j:
                ans=1
                break
        if ans==-1:
            print(0)
        else:
            print(ans)

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):
    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:
import numpy as np
import sys
def input():
	return sys.stdin.readline()[:-1]

def rank(a):
	n, m = len(a), len(a[0])
	#a = np.array([list(map(int, input().split())) for _ in [0]*n])
	if n > m:
		a = a.T
		n, m = m, n
	r = 0
	for i in range(n):
		if a[i][i] != 1:
			for j in range(i+1, m):
				if a[i][j] == 1:
					a[:, [i, j]] = a[:, [j, i]]
					break
			else:
				for j in range(i+1, n):
					if a[j][i] == 1:
						a[[i, j]] = a[[j, i]]
					break
				else:
					break
		if a[i][i] == 0:
			continue

		r += 1
		for j in range(i+1, m):
			a[:, j] += a[i][j] * a[:, i]
			a[:, j] %= 2
		for j in range(i+1, n):
			a[j] += a[j][i] * a[i]
			a[j] %= 2
	
	return r
	#print((pow(2, n+m-1, MOD) - pow(2, n+m-r-1, MOD)) % MOD)

t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	if s[-1] == "1":
		print(1)
		continue
	else:
		i = 0
		while i < n and s[i] == "0":
			i += 1
		if i == n:
			print(0)
			continue
		ok = True
		while i < n:
			z, zo = [], []
			while s[i] == "1":
				zo.append([(a[i] >> k) & 1 for k in range(60)])
				i += 1
			while i < n and s[i] == "0":
				zo.append([(a[i] >> k) & 1 for k in range(60)])
				z.append([(a[i] >> k) & 1 for k in range(60)])
				i += 1
			#print(z, zo)
			if rank(np.array(z)) != rank(np.array(zo)):
				ok = False
				break
		if ok:
			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 j!=n-1:
                if x^a[j]!=0:
                    x=x^a[j]
            else:
                if x^a[j]!=0:
                    x=10
        else:
            if x^a[j]<4:
                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=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
            #数字の逆転
    Q=len(q)
    for j in range(Q):
        t=t^1
        if q[-1-j]==0:
            print(t)
            break

Submission status: Wrong Answer

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

def xor(a,b):
        return a^b# & (1<<0)


def judge0(ini,i,n,t):
        global A
        global S
        an = xor(ini,A[t][i])
        if i>=n-1:
                if an==0:
                        return an
                else:
                        return ini
        else:
                if an==0:
                        if S[t][i+1]=='0':
                                return judge0(an,i+1,n,t)
                        else:
                                return judge1(an,i+1,n,t)
                else:
                        if S[t][i+1]=='0':
                                return judge0(ini,i+1,n,t)
                        else:
                                return judge1(ini,i+1,n,t)


def judge1(ini,i,n,t):
        global A
        global S
        an = xor(ini,A[t][i])
        if i>=n-1:
                if an!=0:
                        return an
                else:
                        return ini
        else:
                if an!=0:
                        if S[t][i+1]=='0':
                                return judge0(an,i+1,n,t)
                        else:
                                return judge1(an,i+1,n,t)
                else:
                        if S[t][i+1]=='0':
                                return judge0(ini,i+1,n,t)
                        else:
                                return judge1(ini,i+1,n,t)
for t in range(T):
        anss=0
        if S[t][0]=='0':
                anss=judge0(anss,0,N[t],t)
        else:
                anss=judge1(anss,0,N[t],t)
        if anss==0:
                ans.append(anss)
        else:
                ans.append(1)
for t in range(T):
        print(ans[t])

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
t=int(input())
def split(word): 
    return [char for char in word] 
for _ in range(t):
  n=int(input())
  a=list(map(int,input().split()))
  s=str(input())
  finalsay=[]
  for i in range(n):
    finalsay.append([])
  m=[]
  for i in range(n):
    k=split('{0:b}'.format(a[i]))
    k.reverse()
    for j in range(70-len(k)):
      k.append('0')
    k.reverse()
    m.append(k)
  finallist=[-1]*70
  for i in range(70):
    for j in range(n):
      if m[n-1-j][i]=='1':
        finallist[i]=n-1-j
        break
  failflag=0
  for i in range(70):
    if finallist[i]==-1:
      continue
    if s[finallist[i]]=='1':
      failflag=1
      break
    else:
      finalsay[finallist[i]].append(i)
  if failflag==1:
    print(1)
    continue
  for A in finalsay:
    r=len(A)
    if r<=1:
      continue
    for j in range(0,r-1):
      for k in range(j+1,r):
        opt1=A[j]
        opt2=A[k]
        for l in range(n):
          if m[n-1-l][opt1]!=m[n-1-l][opt2]:
            if s[n-1-l]=='1':
              failflag=1
            break
        if failflag==1:
          break
      if failflag==1:
        break
    if failflag==1:
      break
  if failflag==1:
    print(1)
  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=input()
    if not "0" in s:
        print(1)
    elif not "1" in s:
        print(0)
    else:
        fir=[]
        sec=[]
        for j in range(n):
            if s[j]=="1":
                fir.append(a[j])
            else:
                sec.append(a[j])
        check=True
        if len(fir)==1 and check:
            check=False
            if (0^fir[0]) in sec:
                print(0)
            else:
                print(1)
        if check:
            fir.sort()
            sec.sort()
            hand=set([])
            for w in fir:
                tt=bin(w)
                cont=max(0,len(tt)-2-1)
                ju=pow(2,cont)
                if w>=ju:
                    hand.add(cont)
                else:
                    hand.add(max(0,cont-1))
            hand=list(hand)
            NG=set([])
            ht=len(hand)
            for h in range(ht-1):
                if hand[h]+1!=hand[h+1]:
                    NG.add(pow(2,hand[h]+1))
                    NG.add(pow(2,hand[h+1]))
            NG=list(NG)
            if NG==[]:
                hand.sort(reverse=True)
                dfg=pow(2,hand[0]+1)
                jflag=False
                for ss in sec:
                    if ss<dfg:
                        jflag=True
                if jflag:
                    print(0)
                else:
                    print(1)
            else:
                NNG=[]
                xxz=len(NG)
                for xx in range(xxz-1):
                    if xx%2==0:
                        NNG.append([NG[xx],NG[xx+1]])
    
                flag=True
                for left , right in NNG:
                    if left<=sec[0] and sec[-1]<right:
                        flag=False
                if flag:
                    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 j!=n-1:
                if x^a[j]!=0:
                    x=x^a[j]
            else:
                if x^a[j]!=0:
                    x=10
        else:
            if j!=n-1:
                if x^a[j]==0:
                    x=x^a[j]
            else:
                if x^a[j]==0:
                    x=0
    if x==0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
t = int(input())
#print(t)

 
for i in range(t):
  n = int(input())
  #print(n)
  A = list(map(int,input().split()))
  #print(A)
  S = list(input())
  #print(S)
  
  x = 0
  j = 0
  
  for j in range(n):
    #print("xは" + str(x))
    #print("jは" + str(j))
    #print("A[j]は" + str(A[j]))
    #print("x ^ A[j]は" + str(x ^ A[j]))
    #print(S[j])
    #print(int(S[j]) == 0)
    #print(bin(x) ^ bin(A[j]))
    #print(bin(x ^ A[j]))
    if ((int(S[j]) == 0) and (x == A[j]) and (x != 0)):
      #print("0kita")
      x = x ^ A[j]
    #elif (S[j] and (x == 0)):
    elif (S[j] and (x != A[j])):
      #print("1kita")
      x = x ^ A[j]
  print(int(bool(x)))

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

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:
                if ans ^ A[i] != 0:
                    ans = ans ^ A[i]
        if ans == 0:
            print('0')
        else:
            print('1')


if __name__ == '__main__':
    main()