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:
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)
            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())
i = 0
ans = []
for _ in range(T):
    x = 0
    N = int(input())
    A = input().replace(" ","")
    S = input()
    for i in range(N):
        x = x ^ int(A[i])
    if x == 0:
        ans.append(0)
    else:
        ans.append(1)
for x in ans:
    print(x)

Submission status: Wrong Answer

Solution code:
import sys 

input = sys.stdin.readline

def main():
  t = int(input().rstrip())
  
  for i in range(t):
    n = int(input().rstrip())
    a = list(map(int, input().rstrip().split()))
    s = input().rstrip()
    x = 0

    for k in range(n):
      if s[k] == "1" and x ^ a[k] != 0:
        x = x ^ a[k]
      if s[k] == "0" and x ^ a[k] == 0:
        x = x ^ a[k]

    if x == 0:
      print(0)
    else:
      print(1)
  
if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
t = int(input())
n = []
a = []
s = []
for i in range(t):
    nn = int(input())
    n.append(nn)
    aa = list(map(int,input().split()))
    a.append(aa)
    ss = input()
    s.append(ss)
for i in range(t):
    x = 0
    for j in range(n[i]):
        if s[i][j] == "0":
            if j < n[i]-1:
                if x ^ a[i][j] ^ a[i][j+1] == 0 and s[i][j+1] == "0":
                    x = x ^ a[i][j]
                elif x ^ a[i][j] == 0 or x != 0:
                    x = x ^ a[i][j]
            elif x ^ a[i][j] == 0:
                x = x ^ a[i][j]
        else:
            if j < n[i]-1:
                if x ^ a[i][j] ^ a[i][j+1] == 1 and s[i][j+1] == "1":
                    x = x ^ a[i][j]
                elif x ^ a[i][j] != 0 or x == 0:
                    x = x ^ a[i][j]
            elif x ^ a[i][j] != 0:
                x = x ^ a[i][j]
    print(x)

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]
    changeable0 = -1
    changeable1 = -1
    for i in range(int(case[0])):
        person = int(persons[i])
        num = int(nums[i])
        if person == 0 and num % 2 == 1:
            changeable0 = i
        elif person == 1 and num % 2 == 1:
            changeable1 = i
    if changeable0 > changeable1:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
import sys 

input = sys.stdin.readline

def main():
  t = int(input().rstrip())
  
  for i in range(t):
    n = int(input().rstrip())
    a = list(map(int, input().rstrip().split()))
    s = input().rstrip()
    x = 0

    for k in range(n):
      if s[k] == "1" and x ^ a[k] != 0:
        x = x ^ a[k]
      if s[k] == "0" and x ^ a[k] == 0:
        x = x ^ a[k]

    if x == 0:
      print(0, end="")
    else:
      print(1, end="")
  
if __name__ == "__main__":
  main()

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 = 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:
def zero(x,a):
    if a == 0 and x==0:
        return x
    elif x==0:
        return x
    elif a ==x:
        x = x^a
        return x
    else:
        x = x^a
        return x

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

T = int(input())

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

Submission status: Wrong Answer

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

def notzero(x,a):
    if a == 0 and x==0:
      x = x^a
      return x
    elif 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:
t = int(input())
for _ in range(t):
	# print()
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	if s[-1] == "1":
		print(1)
		continue

	a1 = [a[i] for i in range(n) if s[i] == "1"]
	a0 = [a[i] for i in range(n) if s[i] == "0"]


	a1 = [list(map(int, "{0:b}".format(item))) for item in a1]
	a0 = [list(map(int, "{0:b}".format(item))) for item in a0]

	m = 0
	if len(a1) > 0:
		m = max([len(item) for item in a1])
	if len(a0) > 0:
		m = max(m, max([len(item) for item in a0]))

	for i in range(len(a1)):
		a1[i] = [0] * (m-len(a1[i])) + a1[i]

	for i in range(len(a0)):
		a0[i] = [0] * (m-len(a0[i])) + a0[i]

	# print("a0", a0)
	# print("a1", a1)

	# print("m", m)
	ones = [set(), set()]

	for i in range(2):
		arr = [a0, a1][i]
		ones_set = ones[i]
		for str_i in range(len(arr)):
			if arr[str_i][str_i:].count(1) > 0:
				max_one = arr[str_i][str_i:].index(1)
			else:
				max_one = -1
			pivot = str_i
			for pivot_c in range(str_i, len(arr)):
				if arr[pivot_c][str_i:].count(1) > 0 and arr[pivot_c][str_i:].index(1) < max_one:
					max_one = arr[pivot_c][str_i:].index(1)
					pivot = pivot_c

			# print("pivot", pivot)
			if max_one != -1:
				ones_set.add(m - str_i - max_one)

				for str_j in range(str_i, len(arr)):
					if str_j != pivot and (arr[str_j][str_i+max_one] == 1):
						for el_i in range(m):
							arr[str_j][el_i] = abs(arr[str_j][el_i] - arr[pivot][el_i])

			arr[pivot], arr[str_i] = arr[str_i], arr[pivot]

			# print("arr", arr)
		# print("ones_set[" + str(i) + "]", ones_set)

	zero_wins = True
	for one_pos in list(ones[1]):
		if one_pos in ones[0]:
			pass
		else:
			zero_wins = False
			break
	if zero_wins:
		print(0)
	else:
		print(1)

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
def main(n,a,s):
  #orders=0
  x=0
  for orders in range(n):
    man = s[orders]
    amn = a[orders]
    if man=="0":
      if x ^ amn == 0:
        x=0
    else:
      notzero = x ^ amn
      if  notzero >0 :
        x=notzero
    orders+=1
  if x==0:
    for orders in range(n):
      man = s[orders]
      amn = a[orders]
      if man=="0":
        if x ^ amn == 0:
          x=0
      else:
        notzero = x ^ amn
        if  notzero >0 and x==0 :
          x=notzero
      orders+=1
    if x==0:
      print(0)
    else:
      print(1)
  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())
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(x)

Submission status: Wrong Answer

Solution code:
def Multiplication1():

    TestCase = int(input()) #入力回数を決める

    for i in range(TestCase):
        Nround = int(input()) #入力回数を決める

        variable = 0

        list_a = list(map(int,input().split()))

        S = str(input())

        #for num in range(Nround):

        num = 0

        while num < Nround:

            variable_1 = variable ^ list_a[num]

            variable_2 = variable

            if S[num] == '1' and variable_1 == 1:
                variable = variable_1

            elif S[num] == '1' and variable_2 == 1:
                variable = variable_2

            elif S[num] == '0' and variable_1 == 0:
                variable = variable_1

            elif S[num] == '0' and variable_2 == 0:
                variable = variable_2

            num = num + 1

        print(variable)

if __name__ == '__main__':
    Multiplication1()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
from collections import Counter
t = int(input())

for _ 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' and x != 0:
            if x ^ a[i] in a[(i + 1) :]:
                if s[a[(i + 1) :].index(x ^ a[i]) + i + 1] == '0':
                    x ^= a[i]
            elif x ^ a[i] == 0:
                x ^= a[i]
            else:
                continue
        if s[i] == '1' and x^a[i] != 0:
            x ^= a[i]
    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]
                elif 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)
    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:
T = int(input())
for i in range(T):
  x = 0
  N = int(input())
  A = list((map(int,input().split())))
  S = list(input())
  for j in range(N):
    if S[j] == '0':
      if(bin(x ^ A[j]) == bin(0)):
        x = 0
      else: x = x
    else:
      if(bin(x ^ A[j]) != bin(0)):
        x = int(bin(x ^ A[j]),2)
      else: x = x
  if(x == 0):print('0')
  else:print('1')

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()
    ok = True
    for i in range(64):
        for j in range(i+1, 64):
            i_s = False
            j_s = False
            pair = False
            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:
                    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:
def main(n,a,s):
  #orders=0
  x=0
  for orders in range(n):
    man = s[orders]
    amn = a[orders]
    if man=="0":
      if x ^ amn == 0:
        x=0
    else:
      notzero = x ^ amn
      if  notzero >0 :
        x=notzero
    orders+=1
  if x==0:
    for orders in range(n):
      man = s[orders]
      amn = a[orders]
      if man=="0":
        if x ^ amn == 0:
          x=0
      else:
        notzero = x ^ amn
        x=notzero
      orders+=1
    if x==0:
      print(0)
    else:
      print(1)
  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:
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.insert(0, [])
    grp.reverse()

    is_ok = True

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

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

        if any(l1):
            is_ok = False
            break

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

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

Submission status: Wrong Answer

Solution code:
import sys

def calcXOR(x, A):
    return (x^A)

def choices(N, AList, S):
    x =0
    for i in range(N):
        if(S[i] == "0"):
            operation_zero = True
        else:
            operation_zero = False
        if(operation_zero == True):
            if(x==0):
                pass
            else:
                x = calcXOR(x, AList[i])
        else:
            if(x == 0):
                x = calcXOR(x, AList[i])
            else:
                y = calcXOR(x, AList[i])
                if(y!= 0):
                    x = y
    return x

if(__name__ == "__main__"):

    T= int( input().strip() )
    NList = [ [0] for i in range(T) ]
    AList = []
    SList = [ [""] for i in range(T) ]

    for t in range(T):
        NList[t] = int( input().strip() )
        List_str = input().strip().split()
        List_int = [0] * NList[t]
        for Num in range(NList[t]):
            List_int[Num] = int(List_str[Num])
        AList.append(List_int)
        SList[t] = input().strip()

    for t in range(T):
        x = choices(NList[t], AList[t], SList[t])
        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()))
    S = input()

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    t = int(args[0])
    ret = []
    for i in range(1, 3*t+1, 3):
        n = int(args[i])
        A = map(int, args[i+1].split())
        S = map(int, tuple(args[i+2]))

        A0 = []
        A1 = []
        for a, s in zip(A, S):
            if s == 1:
                A0.append(a)
            elif s == 0:
                A1.append(a)

        cnt = 0
        X = set([0])
        for a in A1:
            for x in X.copy():
                X.add(a ^ x)
                cnt += 1

        Y = set([0])
        for a in A0:
            for y in Y.copy():
                Y.add(a ^ y)
                cnt += 1
        print(cnt)

        ret.append(1*(1 == len(X & Y)))

    return '\n'.join(map(str, ret))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

Solution code:
import numpy as np
from functools import reduce

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

    if res > 1:
        print("1")
    else:
        print("0")

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

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!=0:
                x=x^l[j]

        if s[j]=="0":
            if l[j]^x==0:
                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:
def zero(x,a):
    if x==0:
        return x
    elif a == 0 and 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 == 0 and 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:
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 == 0 and 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:
def main(n,a,s):
  #orders=0
  x=0
  for orders in range(n):
    man = s[orders]
    amn = a[orders]
    if man=="0":
      if x ^ amn == 0:
        x=0
    else:
      notzero = x ^ amn
      if  notzero >0 :
        x=notzero
    orders+=1
  if 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:
from collections import Counter
t = int(input())

for _ 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' and x != 0:
            if x ^ a[i] in a[(i + 1) :]:
                if s[a[(i + 1) :].index(x ^ a[i]) + i + 1] == '0':
                    x ^= a[i]
            elif x ^ a[i] == 0:
                x ^= a[i]
            else:
                continue
        if s[i] == '1' and x == 0:
            x ^= a[i]
    print(0 if x==0 else 1)

Submission status: Wrong Answer

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

	a1 = [a[i] for i in range(n) if s[i] == "1"]
	a0 = [a[i] for i in range(n) if s[i] == "0"]


	a1 = [list(map(int, "{0:b}".format(item))) for item in a1]
	a0 = [list(map(int, "{0:b}".format(item))) for item in a0]

	m = 0
	if len(a1) > 0:
		m = max([len(item) for item in a1])
	if len(a0) > 0:
		m = max(m, max([len(item) for item in a0]))

	for i in range(len(a1)):
		a1[i] = [0] * (m-len(a1[i])) + a1[i]

	for i in range(len(a0)):
		a0[i] = [0] * (m-len(a0[i])) + a0[i]

	# print("a0", a0)
	# print("a1", a1)

	# print("m", m)
	ones = [set(), set()]

	for i in range(2):
		arr = [a0, a1][i]
		ones_set = ones[i]
		for str_i in range(len(arr)):
			if arr[str_i][str_i:].count(1) > 0:
				max_one = arr[str_i][str_i:].index(1)
			else:
				max_one = -1
			pivot = str_i
			for pivot_c in range(str_i, len(arr)):
				if arr[pivot_c][str_i:].count(1) > 0 and arr[pivot_c][str_i:].index(1) < max_one:
					max_one = arr[pivot_c][str_i:].index(1)
					pivot = pivot_c

			# print("pivot", pivot)
			if max_one != -1:
				ones_set.add(m - str_i - max_one)

				for str_j in range(str_i, len(arr)):
					if str_j != pivot and (arr[str_j][str_i+max_one] == 1):
						for el_i in range(m):
							arr[str_j][el_i] = abs(arr[str_j][el_i] - arr[pivot][el_i])

			arr[pivot], arr[str_i] = arr[str_i], arr[pivot]

			# print("arr", arr)
		# print("ones_set[" + str(i) + "]", ones_set)

	zero_wins = True
	for one_pos in list(ones[1]):
		if one_pos in ones[0]:
			pass
		else:
			zero_wins = False
			break
	if zero_wins:
		print(0)
	else:
		print(1)

Submission status: Wrong Answer

Solution code:
t=int(input())
#h1,m1,h2,m2,k=map(int,input().split())
#a=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
#l=[list(input().split()) for i in range(n)]

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

        k=0
        while s[n-1-k]=="0" and k<n:
                k+=1
                
        for j in range(n-k):
                if s[j]=="0":
                        if x>x^a[j]:
                                x=x^a[j]
                else:
                        if x<x^a[j]:
                                x=x^a[j]

        b=set(a[n-k:])
        for j in range(k):
                if x in b:
                        x=0
                        break
                else:
                        if len(bin(x))>len(bin(x^a[n-k+j])):
                                x=x^a[n-k+j]
        if x==0:
                print(0)
        else:
                print(1)