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 judge0(ini,i,n,t):
        global A
        global S
        an = 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 an==A[t][i+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)


def judge1(ini,i,n,t):
        global A
        global S
        an = 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 an==A[t][i+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)
        if anss==0:
                ans.append(anss)
        else:
                ans.append(1)
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):
    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:
# 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 not ok:
                    break
                if len(selected[index]) > 0:
                    done = [0] * len(selected[index])
                    for i in range(index - 1, -1, -1):
                        if 0 not in done:
                            break
                        vals = []
                        for kk, shif in enumerate(selected[index]):
                            vals.append((A[i] >> shif) % 2)
                            if (A[i] >> shif) % 2:
                                done[kk] = 1
                        if 1 in vals and 0 in vals and S[i] == '1':
                            ok = False
                            break

            if not ok:
                print(1)
            else:
                print(0)

if __name__ == "__main__":
    run()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def ref(N, A, S):
    if S[-1] == '1':
        return 1

    if N > 20:
        N = 20
        A = A[-20:]
        S = S[-20:]

    def f(i, x):
        if i == N:
            if x == 0:
                return 0
            else:
                return 1
        p = int(S[i])
        if f(i+1, x ^ A[i]) == p:
            return p
        if f(i+1, x) == p:
            return p
        return p ^ 1

    return f(0, 0)

def slv(N, A, S):
    if S[-1] == '1':
        return 1
    from random import choices
    al = [[], []]
    for s, a in zip(S, A):
        al[int(s)].append(a)

    if len(al[1]) == 0:
        return 0

    # al[0] = []
    # for i in range(N-1, -1, -1):
    #     if S[i] == '1':
    #         break
    #     al[0].append(A[i])


    a0 = set(choices(list(set(al[0])), k=20))
    a1 = set(choices(list(set(al[1])), k=20))
    p0 = set([0])
    for a in a0:
        t = set()
        for v in p0:
            t.add(v ^ a)
        p0 |= t

    p1 = set([0])
    for a in a1:
        t = set()
        for v in p1:
            t.add(v ^ a)
        p1 |= t

    for v in p1:
        if v not in p0:
            return 1
    return 0


def main():
    T = read_int()
    for _ in range(T):
        N = read_int()
        A = read_int_n()
        S = read_str()
        print(ref(N, A, S))


    # import random
    # # N = 35
    # # A = [random.randint(1, 10**18) for _ in range(N)]
    # # S = random.choices('01', k=N-1)
    # # S.append('0')
    # # print(ref(N, A, S))

    # while True:
    #     N = 200
    #     A = [random.randint(1, 10**18) for _ in range(N)]
    #     S = random.choices('01', k=N-1)
    #     S.append('0')


    #     # A = [4, 16, 2, 10, 3, 13, 6, 4, 1, 3]
    #     # S = ['0', '0', '1', '0', '0', '0', '0', '0', '0', '0']
    #     # print(A)
    #     # print(S)
    #     a = ref(N, A, S)

    #     # b = ref(N, A, S)
    #     # if a != b:
    #     #     print(a, b)
    #     #     break


if __name__ == '__main__':
    main()

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()
    tools = []
    ok = True
    for itr, g in enumerate(group):
        if itr % 2 == 0:
            for item in g:
                tools.append(item)
        else:
            tl = tools[:]
            index = 0
            for i in range(64, -1, -1):
                flag = 0
                for j in range(index, len(tl)):
                    if tl[j] & (1 << i):
                        flag = 1
                        tl[index], tl[j] = tl[j], tl[index]
                        break
                for j in range(index + 1, len(tl)):
                    if tl[j] & 1 << i:
                        tl[j] ^= tl[index]
                if flag == 1:
                    index += 1
            for item in g:
                current = 0
                for val in tl:
                    index = len(bin(val)) - 3
                    if val & 1 << index != current & 1 << index:
                        current ^= val
                if current != item:
                    ok = False
    if ok:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

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


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


def solve(N, A, S):
    if S[-1] == "1":
        return 1
    P = [0, 0]
    C = [0, 0]
    for s, a in zip(S, A):
        if s == "0":
            P[0] |= a
            C[0] += bin(a).count("1")
        elif s == "1":
            P[1] |= a
            C[1] += bin(a).count("1")
        else:
            raise ValueError()
    return 0 if P[0] & P[1] == P[0] else 1


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

Submission status: Wrong Answer

Solution code:
K=60

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

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

    L=len(M)
    E=M+C


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

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

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

        if (E[k]>>i)%2:
            J+=1
            F=[]
            for j in range(N):
                F.append((E[j]>>i)%2)
                
            for I in range(K):
                if (i!=I) and ((E[k]>>I)%2):
                    for j in range(N):
                        E[j]^=(F[j]<<I)
        
    p=0
    while 0 in E[:L]:
        p+=1
        E.remove(0)

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

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

    print(H)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
1

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    ans = '0'
    for i in range(N):
        if S[i]=='1':
            l = []
            for j in range(i+1,N):
                if S[j]=='0':
                    l.append(A[j])
            l.sort()
            for k in range(len(l)):
                for j in range(len(l)-1):
                    if l[j+1]^l[j] < l[j+1]:
                        l[j+1],l[j] = l[j],l[j+1]^l[j]
            s = A[i]
            for j in range(len(l)-1,-1,-1):
                if s^l[j] < s:
                    s ^= l[j]
            if s != 0:
                ans = '1'
    print(ans)
def main():
    T = int(input())
    for t in range(T):
        solve()

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=str(input())
    for j in range(n):
        a[j]=a[j]&1
    ans=0
    for j in range(n):
        if a[-1-j]==1:
            ans=int(s[-1-j])
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def ref(N, A, S):
    if S[-1] == '1':
        return 1

    if N > 20:
        N = 20
        A = A[:-20]
        S = S[:-20]

    def f(i, x):
        if i == N:
            if x == 0:
                return 0
            else:
                return 1
        p = int(S[i])
        if f(i+1, x ^ A[i]) == p:
            return p
        if f(i+1, x) == p:
            return p
        return p ^ 1

    return f(0, 0)

def slv(N, A, S):
    if S[-1] == '1':
        return 1
    from random import choices
    al = [[], []]
    for s, a in zip(S, A):
        al[int(s)].append(a)

    if len(al[1]) == 0:
        return 0

    # al[0] = []
    # for i in range(N-1, -1, -1):
    #     if S[i] == '1':
    #         break
    #     al[0].append(A[i])


    a0 = set(choices(list(set(al[0])), k=20))
    a1 = set(choices(list(set(al[1])), k=20))
    p0 = set([0])
    for a in a0:
        t = set()
        for v in p0:
            t.add(v ^ a)
        p0 |= t

    p1 = set([0])
    for a in a1:
        t = set()
        for v in p1:
            t.add(v ^ a)
        p1 |= t

    for v in p1:
        if v not in p0:
            return 1
    return 0


def main():
    T = read_int()
    for _ in range(T):
        N = read_int()
        A = read_int_n()
        S = read_str()
        print(ref(N, A, S))


    # import random
    # # N = 35
    # # A = [random.randint(1, 10**18) for _ in range(N)]
    # # S = random.choices('01', k=N-1)
    # # S.append('0')
    # # print(ref(N, A, S))

    # while True:
    #     N = 200
    #     A = [random.randint(1, 10**18) for _ in range(N)]
    #     S = random.choices('01', k=N-1)
    #     S.append('0')


    #     # A = [4, 16, 2, 10, 3, 13, 6, 4, 1, 3]
    #     # S = ['0', '0', '1', '0', '0', '0', '0', '0', '0', '0']
    #     # print(A)
    #     # print(S)
    #     a = ref(N, A, S)

    #     # b = ref(N, A, S)
    #     # if a != b:
    #     #     print(a, b)
    #     #     break


if __name__ == '__main__':
    main()

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 not ok:
                    break
                if len(selected[index]) > 0:
                    done = [0] * len(selected[index])
                    for i in range(index - 1, -1, -1):
                        if 0 not in done:
                            break
                        vals = []
                        for kk, shif in enumerate(selected[index]):
                            vals.append((A[i] >> shif) % 2)
                            if (A[i] >> shif) % 2:
                                done[kk] = 1
                        if 1 in vals and 0 in vals and S[i] == '1':
                            ok = False
                            break
                        elif 0 not in vals and S[i] == '0':
                            break
                        
            if not ok:
                print(1)
            else:
                print(0)

if __name__ == "__main__":
    run()

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:
                count=0
                c=0
                t=x
                b=x^a[j]
                while(t):
                    t=t&(t-1)
                    count=count+1
                while(b):
                    b=b&(b-1)
                    c=c+1
                if(c>count):
                    x=x^a[j]
                    
        elif(s[j]=="0"):
            if(x!=0):
                count=0
                c=0
                t=x
                b=x^a[j]
                while(t):
                    t=t&(t-1)
                    count=count+1
                while(b):
                    b=b&(b-1)
                    c=c+1
                if(c<count):
                    x=x^a[j]
                    

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

Submission status: Wrong Answer

Solution code:
T = int(input())
N_list = []
A_list = []
S_list = []
for i in range(T):
  N = int(input())
  AL = list(map(int,input().split()))
  S = str(input())
  N_list.append(N)
  A_list.append(AL)
  S_list.append(S)

Submission status: Wrong Answer

Solution code:
dit = 0


T = int(input())
for t in range(0,T):
    N = int(input())
    A = list(map(int, input().split()))
    S = str(input())   
    if S[N-1]=="1":
        print(1)
    else:
        if "1" not in S:
            print(0)
        else:
            for i in range(1,N):
                if S[-i]=="0":
                    dit = dit + 1
                    continue
                else:
                    break
                if A[i] == A[0]:
                    continue
                else:
                    print(0)
                    exit()

Submission status: Wrong Answer

Solution code:
t = int(input())
n,a,s = [],[],[]
for i in range(t):
    n.append(int(input()))
    a.append([int(x) for x in input().split(' ')])
    s.append(input())

def ret_or(aa, ss, l, zero):
    ret = 0
    for j in range(l):
        if ss[j] == '1' or zero:
            ret |= aa[j]
    return ret

for i in range(t):
    if s[i][-1] == '1':
        print(1)
    else:
        l = s[i].rfind('1')+1
        aa = a[i][:l]
        ss = s[i][:l]
        sets = ret_or(aa, ss, l, False)
        aa = a[i][l:]
        ss = s[i][l:]
        zeros = ret_or(aa, ss, n[i] - l, True)
        if sets == zeros:
            print(0)
        else:
            print(1)

Submission status: Wrong Answer

Solution code:
def resolve():
    t = int(input())
    for _ in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        s = input()
        for i in range(60):
            x = 0
            for j in range(n):
                if s[j] == "0":
                    if x == 1:
                        if a[j] & (1 << i):
                            x = 0
                else:
                    if x == "0":
                        if a[j] & (1 << i):
                            x = 1
            if x == 1:
                print(1)
                break
        else:
            print(0)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

    dp = [[0, 0] for i in range(N)]
    # 人１がビットを最後に立てた後に０にできるなら０にならない
    L = max(A).bit_length()

    res = 0
    s = [set() for i in range(L)]
    for i in range(L):
        flag = False
        for j in range(N):
            if (A[j] >> i) % 2 == 1:
                if S[j] == '0':
                    flag = False
                    s[i].add(j)
                else:
                    flag = True
                    s[i] = set()

        if flag:
            res = 1
            break
    if res or S[-1] == '1':
        print(res)
    else:

        B = [A[i] for i in range(N) if S[i] == '0']
        ss = B[0]
        for x in B[1:]:
            ss &= x

        for i in range(L):
            l = len(s[i])
            if l == 1 and ss:
                if (ss >> i) % 2 == 0:
                    res = 1
                    break
        print(res)

Submission status: Wrong Answer

Solution code:
import sys
from copy import deepcopy

def canMake(k, Nums):#Numsにある数でkを作れるか
    index = 0
    for i in reversed(range(60)):
        if k & (1 << i) != (1 << i): continue
        flag = 0
        for j in range(index, len(Nums)):
            if Nums[j] & (1 << i) == (1 << i):
                Nums[index], Nums[j] = Nums[j], Nums[index]
                break
        else: return False
        for j in range(index + 1, len(Nums)):
            Nums[j] ^= Nums[index]
    return True


def solve():
    input = sys.stdin.readline
    T = int(input())
    Ans = [0] * T
    for t in range(T):
        N = int(input())
        A = [int(a) for a in input().split()]
        S = input().strip("\n")
        used = []
        for i in reversed(range(N)):
            if S[i] == "0":
                used.append(A[i])
            else:
                compare = deepcopy(used)
                if not canMake(A[i], compare):
                    Ans[t] = 1
                    break
    
    print(*Ans, sep="\n")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
t = int(input())
try_arr = []
for i in range(t):
    n = int(input())
    a = input().split()
    s = str(input())
    x = bin(0)
    try_arr.append([n,a,s,x])
for arr in try_arr:
    for i in range(arr[0]):
        if arr[2][i] == '0':
            # xが0じゃ無いかつ、排他論理和が0になる場合はxを0に変えてやる
            if arr[3] != bin(0) and bin(int(arr[3], 2) ^ int(arr[1][i])) == bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            else:
                pass
        else:
            # xが0の場合かつ排他論理和が0じゃ無い時
            if arr[3] == bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            # 次の番号が0か1で対応が変わる
            else:
                if len(arr[1]) != i+1 and arr[2][i+1] == '0':
                    if bin(int(arr[3], 2) ^ int(arr[1][i])) != bin(0) and bin(int(arr[3], 2) ^ int(arr[1][i + 1])) == bin(0):
                        arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
                else:
                    pass
    if arr[3] == bin(0):
        print('0')
    else:
        print('1')

Submission status: Wrong Answer

Solution code:
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s = input()
    p1 = []
    p0 = []
    for i, ss in enumerate(s):
        p1.append(a[i]) if ss == "1" else p0.append(a[i])
    res1 = 0
    for p11 in p1:
        res1 |= p11
    res0 = 0
    for p00 in p0:
        res0 |= p00
    bin1 = str(bin(res1))
    bin0 = str(bin(res0))
    if len(bin1) != len(bin0):
        print(1)
    else:
        flg = True
        for i in range(len(bin0)):
            if bin1[i] != bin0[i]:
                flg = False
        print(0 if flg else 1)

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
  sums=[]
  for i in range(n):
    sums.append([])
    value=0
    for j in range(70):
      value+=int(m[i][j])
      sums[i].append(value)
  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 i in range(69):
    for j in range(i+1,70):
      for l in range(n):
        if (sums[n-1-l][j]-sums[n-1-l][i])%2==1:
          if s[n-1-l]=='1':
            failflag=1
          break
  if failflag==1:
    print(1)
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
K=60

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

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

    L=len(M)
    E=M+C


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

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

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

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

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

    print(H)