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())
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)
        ans.append(anss)
for t in range(T):
        print(ans[t])

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
t = int(input())
def judge(mat,x,pivot):
  b = x.bit_length()
  cnt = 0
  for i in range(b)[::-1]:
    if x&1<<i:
      if i not in pivot:
        return False
      for j in range(cnt,len(mat)):
        if mat[j]&1<<i:
          x ^= mat[j]
          cnt = mat[j]
          break
  return True
def add(mat,x,pivot):
  b = x.bit_length()
  cnt = 0
  for i in range(b)[::-1]:
    if x&1<<i:
      if i in pivot:
        for j in range(cnt,len(mat)):
          if mat[j]&1<<i:
            x ^= mat[j]
            cnt = 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)
            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())
l1=[]
l2=[]
x=0
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    s=input()
    for j in range(n):
        if s[j]=="1":
            if l[j]!=x:
                x=x^l[j]

        if s[j]=="0":
            if l[j]==x:
                x = x ^ l[j]
    l1.append(x)
for i in l1:
    if i!=0:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit
import numpy as np

setrecursionlimit(10 ** 7)

t = int(stdin.readline().rstrip())

for _ in range(t):
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    s = stdin.readline().rstrip()
    b = []
    c = []
    for i in range(n):
        if s[i] == "0":
            b.append(a[i])
        else:
            c.append(a[i])
    if len(b) < len(c):
        print(1)
        exit()
    b = np.array(b,dtype=np.int64)
    c = np.array(c,dtype=np.int64)
    b_li = np.array([((b>>i)&1).sum() for i in range(64)],dtype=np.int64)
    c_li = np.array([((c>>i)&1).sum() for i in range(64)],dtype=np.int64)
    if np.count_nonzero(b_li<c_li):
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
T = int(input()) # テストケースの数

x = 0
for i in range(T):
    N = int(input()) # ラウンド数
    A = list(map(int, input().strip().split())) # xとの排他的論理和を求めるリスト
    # A = list(map(lambda x: bin(x), A)) # 0,1で表示
    S = input() # 行動する人
    S = list(S)
    S = [int(s) for s in S] # リスト型数値に変換

    for j in range(N):
        a = x^A[j]
        if S[j] == 0: # 0が行動
            if x == 1:
                if a != 1:
                    x = 0
        else: # 1が行動
            if x == 0:
                if a == 1:
                    x = 1

    print(x)

Submission status: Wrong Answer

Solution code:
T = int(input())
for t in range(T):
    x = 0
    N = int(input())
    A = [int(i) for i in input().split(' ')]
    S = [int(i) for i in list(input())]
    for n in range(N):
        if S[n]==0 and x^(A[n]-1)==1 and (x!=S[n])==0:
            x = x^(A[n]-1)
        elif S[n]==1 and x^(A[n]-1)==0 and (x!=S[n])==1:
            x = x^(A[n]-1)
        else :
            pass
    print(x)

Submission status: Wrong Answer

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

from collections import deque

def main():
    n=int(input())
    a=LI()
    s=[int(ss) for ss in list(input())]
    b=deque(sorted([bin(q)[::-1] for q in a]))
    x=0
    print(b)
    for q in range(n):
        # x^=q
        if s[q]==0:
            tmp=b.popleft()
            if tmp[0]=="1":continue
            tmp=int(tmp[::-1],0)
            x^=tmp
        else:
            tmp=b.pop()
            if tmp[0]=="0":continue
            tmp=int(tmp[::-1],0)
            x^=tmp
        
    print(0 if x==0 else 1)

t=int(input())
for _ in range(t):
    main()

# 入力例1でしんでるけど

Submission status: Wrong Answer

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

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

T = int(input())

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    t = int(input())
    for i in range(t):
        n = int(input())
        A = list(map(int, input().split()))
        s = input()
        X = tuple(A[i] for i in range(n) if s[i] == "1")
        Y = tuple(A[i] for i in range(n) if s[i] == "0")

        res = set(Y)
        for y in Y:
            for x in X:
                res.add(x ^ y)

        for x in X:
            if x not in res:
                print(1)
                break
        else:
            print(0)


if __name__ == '__main__':
    resolve()

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


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()))
    S = input()

    x = 0
    for i in range(N):
        if S[i] == "0":
            if x != 0:
                x = x ^ A[i]
        else:
            if x == 0:
                x = x ^ A[i]
    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([int(i) for i in input().split(" ")] )
  S.append(input())


results = []
for k,v in enumerate(A):
  x = 0
  for vk, vv in enumerate(v): 
    player = list(S[k])
    if player[vk] == "0" :
      if x^vv<x:
        x=x^vv
      else:
        x=x
    else :
      if x^vv != 0: 
        x=x^vv
      else:
        x=x
  results.append("0" if x==0 else "1") 
print("\n".join(results))

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]))
            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]))
            else:
                pass
    if x == 0:
        print(0)
    else:
        print(1)

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])
    result.reverse()

    for i in range(len(result)):
        a, b = result[i]
        for j in range(i + 1, len(result)):
            if result[j][0] & b:
                result[j][0] ^= b
    result = set(map(itemgetter(0), result))

    return result


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

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

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

    is_ok = True

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

    if is_ok:
        buf.append(0)

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit
import numpy as np

setrecursionlimit(10 ** 7)

t = int(stdin.readline().rstrip())

for _ in range(t):
    n = int(stdin.readline().rstrip())
    a = list(map(int,stdin.readline().rstrip().split()))
    s = stdin.readline().rstrip()
    b = []
    c = []
    for i in range(n):
        if s[i] == "0":
            b.append(a[i])
        else:
            c.append(a[i])
    b = np.array(b,dtype=np.int64)
    c = np.array(c,dtype=np.int64)
    b_li = np.array([((b>>i)&1).sum() for i in range(64)],dtype=np.int64)
    c_li = np.array([((c>>i)&1).sum() for i in range(64)],dtype=np.int64)
    if np.count_nonzero(b_li<c_li):
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(item) for item in input().split()]
    s = input().rstrip()
    if s[-1] == "1":
        print(1)
        continue
    group = []
    prev = "-1"
    for ch, num in zip(s, a):
        if prev != ch:
            group.append([])
        group[-1].append(num)
        prev = ch
    group.reverse()
    for i in range(64):
        for j in range(i+1, 64):
            i_s = False
            j_s = False
            pair = False
            ok = True
            for itr, g in enumerate(group):
                has_pair = False
                has_i = False
                has_j = False
                for item in g:
                    ival = item >> i & 1
                    jval = item >> j & 1
                    if ival and jval:
                        has_pair = True
                    elif ival:
                        has_i = True
                    elif jval:
                        has_j = True
                if has_pair and has_i:
                    has_j = True
                if has_pair and has_j:
                    has_i = True
                if has_i and has_j:
                    has_pair = True

                if itr % 2 == 0:
                    if has_i and has_j:
                        ok = True
                        break
                    pair = pair or has_pair
                    i_s = i_s or has_i
                    j_s = j_s or has_j
                else:
                    if has_i and not i_s:
                        ok = False
                        break
                    if has_j and not j_s:
                        ok = False
                        break
                    if has_pair and not pair:
                        ok = False
                        break

            if not ok:
                break
        if not ok:
            break
    if not ok:
        print(1)
    else:
        print(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 = input()

  # i番目の人は、x^Aするかどうかを考える
  # Sのi番目が0ならx=0になるときだけ変更する、1ならx!=0になるときだけ変更する

  # Sが111と最後まで続くとき、特別なケースが存在する
  count = 0
  for s in range(N):
    if S[N-s-1] == "0":
      count += 1
    else:
      break
      
  for i in range(N):
    if S[i] == "0":
      if i > N-count:
        y = x
        for k in range(i, N):
          y = y ^ A[k]
        if y == 0:
          x = 0
          break
      
      elif x ^ A[i] == 0:
        x = x ^ A[i]
        #print("x=",x)
      
    else:
      if x ^ A[i] != 0:
        x = x ^ A[i]
        #print("x=",x)
  if x == 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 = [int(i) for i in input().split(' ')]
    S = [int(i) for i in list(input())]
    for n in range(N):
        if S[n]==0 and x^(A[n]-1)==1:
            x = x^(A[n]-1)
        elif S[n]==1 and x^(A[n]-1)==0:
            x = x^(A[n]-1)
        else :
            pass
    print(x)

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==1:
                        return an
                else:
                        return ini
        else:
                if an==1:
                        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)
        ans.append(anss)
for t in range(T):
        print(ans[t])

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:
                pass
            else:
                x = int(int(x) ^ int(A1[i]))
        if int(S1[i]) == 1:
            if x == 0 or int(int(x) ^ int(A1[i])) != 0:
                x = int(int(x) ^ int(A1[i]))
            else:
                pass
    if x == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def least_bit_set(x):
    return x & (-x)


def delete_zeros_from(values, start):
    i = start
    for j in range(start, len(values)):
        if values[j] != 0:
            values[i] = values[j]
            i += 1
    del values[i:]


def eliminate(values):
    values = list(values)
    i = 0
    while True:
        delete_zeros_from(values, i)
        if i >= len(values):
            return values
        j = i
        for k in range(i + 1, len(values)):
            if least_bit_set(values[k]) < least_bit_set(values[j]):
                j = k
        values[i], values[j] = (values[j], values[i])
        for k in range(i + 1, len(values)):
            if least_bit_set(values[k]) == least_bit_set(values[i]):
                values[k] ^= values[i]
        i += 1


def in_span(x, eliminated_values):
    for y in eliminated_values:
        if least_bit_set(y) & x != 0:
            x ^= y
    return x == 0

tt=int(input())
for qq in range(0,tt):
	n=int(input())
	A=input().split(" ")
	s=input()
	x=[]
	values=[]
	for i in range(0,len(s)):
		if(s[i]=='1'): x.append(int(A[i]))
		else: values.append(int(A[i]))
	eliminated_values = eliminate(values)
	#   x = int(input())
	ok = 0
	if(s[len(s)-1]=='1'): ok=1
	for i in x:
		if(in_span(int(i), eliminated_values)==False):
			ok=1
			break
	print(ok)

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 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 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:
if __name__ == '__main__':
    T = int(input().strip())
    for i in range(T):
        N = int(input().strip())
        A = list(map(int, input().strip().split(" ")))
        S = input().strip()
        x = 0
        x_bin = str(bin(x))[2:].zfill(100)

        for j in range(N):
            z = x ^ A[j]
            z_bin = str(bin(z))[2:].zfill(100)

            if S[j] == "0":
                if z_bin.count("0") > x_bin.count("0"):
                    x = z
                    x_bin = z_bin

            else:
                if z_bin.count("0") < x_bin.count("0"):
                    x = z
                    x_bin = z_bin

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

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):
        if s[i] == '0':
            x = x^a[i]
            if not x == 0:
                x = x^a[i]
        else:
            x = x^a[i]
            if x == 0:
                x = x^a[i]

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

t = INT()

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

    a = LIST()

    s = input()

    ones = []
    zeros = []

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

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

    for j in range(61):
        flag = 0
        numones = 0
        for el in ones:
            if((el>>j)&1):
                flag = 1
                numones+=1

        if(flag==0):
            oUtil[j] = '0'
        elif(numones==len(ones)):
            oUtil[j] = '1'

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


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

    # print(oUtil, zUtil)
    print(ans)

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

Submission status: Wrong Answer

Solution code:
T = int(input())


def solv():
  N = int(input())
  A = list( map(int, input().split()) )	# 1 2 3 4 5 ...
  S = input
  x = 0

  if S[-1]=="1":
    print(1)
    exit()



  print(2)




for t in range(T):
  solv

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):
        if s[i] == '0':
            if not x == 0:
                x = x^a[i]
        else:
            x = x^a[i]
            if x == 0:
                x = x^a[i]

    if x == 0:
        ans.append('0')
    else:
        ans.append('1')

for i in ans:
    print(i)

Submission status: Wrong Answer

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


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


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


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


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


t = inp()

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

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

    print(x)

Submission status: Wrong Answer

Solution code:
def resolve():
    T = int(input())

    for t in range(T):
        n = int(input())
        A = list(map(int, input().split()))
        s = input()
        a = 0
        b = 0

        i = 0
        state = 0
        while i < n:
            if s[i] == "0":
                while i < n and s[i] == "0":
                    a |= A[i]
                    i += 1
            else:
                while i < n and s[i] == "1":
                    b |= A[i]
                    i += 1

            if a - b == 0:
                state = 0
                a = 0
                b = 0
            else:
                state = 1
        print(state)

resolve()

Submission status: Wrong Answer

Solution code:
def least_bit_set(x):
    return x & (-x)


def delete_zeros_from(values, start):
    i = start
    for j in range(start, len(values)):
        if values[j] != 0:
            values[i] = values[j]
            i += 1
    del values[i:]


def eliminate(values):
    values = list(values)
    i = 0
    while True:
        delete_zeros_from(values, i)
        if i >= len(values):
            return values
        j = i
        for k in range(i + 1, len(values)):
            if least_bit_set(values[k]) < least_bit_set(values[j]):
                j = k
        values[i], values[j] = (values[j], values[i])
        for k in range(i + 1, len(values)):
            if least_bit_set(values[k]) == least_bit_set(values[i]):
                values[k] ^= values[i]
        i += 1


def in_span(x, eliminated_values):
    for y in eliminated_values:
        if least_bit_set(y) & x != 0:
            x ^= y
    return x == 0

tt=int(input())
for qq in range(0,tt):
	n=int(input())
	A=input().split(" ")
	s=input()
	x=[]
	values=[]
	for i in range(0,len(s)):
		if(s[i]=='1'): x.append(int(A[i]))
		else: values.append(int(A[i]))
	eliminated_values = eliminate(values)
	#   x = int(input())
	ok = 0
	for i in x:
		if(in_span(int(i), eliminated_values)==False):
			ok=1
			break
	print(ok)

Submission status: Wrong Answer

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