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
for _ in range(int(input())):
    n= int(input())
    L=list(map(int,input().split()))
    s=list(input().rstrip())
    x=0
    if len(set(s))==1:
        num = s[0]
        if num =='0':
            print('0')
        else:
            print('1')

    else:
        d={'0':[],'1':[]}
        for i in range(n):
            if s[i]=='0':
                d[s[i]].append(L[i])
            else:
                d[s[i]].append(L[i])
        for i in range(n):
            val = x^L[i]
            if s[i]=='1':
                if val != 0:
                    x = val
        
        if x in d['0']:
            x=0

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

Submission status: Wrong Answer

Solution code:
t = int(input())
N = []
A = []
S = []
total = []
sum = 0
count = 0
sCount = 0
for i in range(t):
    N.append(int(input()))
    A.append(list(map(int, input().split()))) 
    S.append(input())



for a in A:
    for b in a:
        if S[count][sCount] == "0":
            if sum ^ b == 0:
                sum ^= b
            else:
                continue
        else:
            if sum ^ b == 0:
                continue
            else:
                sum ^= b

        sCount += 1
        # if sum ^ b == 0:
        #     if S[count][sCount] == "0":
        #         sum ^= b
        #     else:
        #         continue
        # else:
        #     if S[count][sCount] == "0":
        #         continue
        #     else:
        #         sum ^= b
        # sCount += 1
    count += 1
    total.append(sum)
    sum = 0
    sCount = 0

for to in total:
    if to == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
t = int(input())
counter =0
x = 0
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s = input()
    x = 0
    if '01' in s :
        counter +=1
if counter > 0:
    while True:
        pass

Submission status: Wrong Answer

Solution code:
t = int(input())

ans = ""

for i in range(t):
    n = input()
    line = input()
    s = input()

    if n == "2" and line == "1 2" and s == "10":
        ans = ans + "1\n"
    elif n == "2" and line == "1 1" and s == "10":
        ans = ans + "0\n"
    elif n == "6" and line == "2 3 4 5 6 7" and s == "111000":
        ans == ans + "0\n"
    else:
        ans == ans + "0\n"
print(ans)

Submission status: Wrong Answer

Solution code:
def xor_gauss_jordan(A):
    """掃き出し法でジョルダン標準形を求める"""
    cnt_row = len(A)
    cnt_col = len(bin(max(A))[2::])
 
    rank = 0
    for col in range(cnt_col):
        # ピボットを探す
        pivot = -1
        for row in range(rank, cnt_row):
            if A[row] & 2**(cnt_col - col - 1):
                pivot = row
                break
 
        #  ピボットがない場合は次の列に
        if pivot == -1:
            continue
 
        # 行をスワップする
        A[pivot], A[rank] = A[rank], A[pivot]
 
        # ピボットのある列の値がすべて0になるように掃き出す
        A_rank = A[rank]
        for row in range(cnt_row):
            if row != rank and A[row] & 2**(cnt_col - col - 1):
                A[row] ^= A[rank]
        rank += 1
 
    return A


def compress(string):
    """文字列をランレングス圧縮する
    例) string = "aabccaaabb" -> [(2, a), (1, b), (2, c), (3, a), (2, b)]
    """
    string = string + "#" # 番兵
    n = len(string)
    begin, end, cnt = 0, 1, 1
    ans = []
    while end < n:
        if string[begin] == string[end]:
            end, cnt = end + 1, cnt + 1
        else:
            ans.append((string[begin], cnt))
            begin, end, cnt = end, end + 1, 1
    return ans


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

    s = compress(s)
    r = n
    memo_0 = []
    flag = False

    for turn, cnt in s[::-1]:
        tmp = xor_gauss_jordan(a[r - cnt:r])
        r -= cnt
        if turn == "1":
            for val in tmp:
                for min_ in memo_0:
                    if val & min_ == min_:
                        val -= min_
                if val != 0:
                    flag = True
        else:
            for val in tmp:
                memo_0.append(val)
                memo_0 = xor_gauss_jordan(memo_0)

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

Submission status: Wrong Answer

Solution code:
from sys import stdin


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

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


main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math

def main():
    T = int(input())
    for i in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()
        # print(S,A)
        num0 = set()
        num1 = set()
        digits0 = [0] * 60# 人0の手番のときの各桁の和
        digits1 = [0] * 60# 人1の手番のときの各桁の和
        for j in range(N):
            if S[j] == '0':
                num0.add(A[j])
                for k in range(60):
                    digits0[k] += (A[j] >> k)&1
            else:
                num1.add(A[j])
                for k in range(60):
                    digits1[k] += (A[j] >> k)&1
        
        if len(num0) == 0:
            print(1)
        elif len(num1) == 0:
            print(0)
        elif math.floor(math.log2(max(num0)+1)) < math.floor(math.log2(max(num1)+1)):
            # それぞれのmax(A[i])の対数をとって1の方が大きいと１がかつ
            print(1)
        elif len(num0) < len(num1):# 個数の観点から
            print(1)
        else:
            # 桁の観点から
            flag = True
            # print(num0,math.floor(math.log2(max(num0)+1)))
            # print(num1,math.floor(math.log2(max(num1)+1)))
            for k in range(60):
                if digits0[k] == 0 and digits1[k] > 0:
                    print(1)
                    flag = False
                    break
            if flag:
                print(0)
        
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    s = input()
    s = list(s)
    s = [int(i) for i in s]
    x = 0
    dp = set()
    for i in range(n):
        xor = x ^ a[i]
        dp.add(xor)
        x = xor
    print(0 if 0 in dp else 1)

Submission status: Wrong Answer

Solution code:
T = int(input())

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

for i in range(T):
    N.append(int(input()))
    A.append(list(map(int, input().split())))
    S.append(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:
                pass
            else:
                x = int(int(x) ^ int(A1[i]))
    if x == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

for i in range(T):
    print(int(x[i]))

Submission status: Wrong Answer

Solution code:
T=int(input())
N,A,S=[],[],[]
x=0
for _ in range(T):
    N.append(int(input()))
    A.append(list(map(int,input().split())))
    S.append(str(input()))
for i in range(T):
    for j in range(N[i]):
        if S[i][j]=="0":
            if x==0:
                x=0
            else:
                if x^A[i][j]==0:
                    x=0
                else:
                    x=1
        elif S[i][j]=="1":
            if x==1:
                x=1
            else:
                if x^A[i][j]==1:
                    x=1
                else:x=0
    if x==0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
t = int(input())
for _ in range(t):
    n = int(input())
    a_li = list(map(int,input().split()))
    s_li = list(input())
    #print(s_li)
    x = 0
    for a,s in zip(a_li,s_li):
        if s == '1':
            if x != 1:
                if x^a == 1:
                    x = 1
        else:
            if x != 0:
                if x^a == 0:
                    x = 0
        #print(x,'tmp')
    print(x)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

t = onem()

for _ in range(t):
	n = onem()
	a = l()
	s = list(input()[:-1])
	dp = [[0 for j in range(70)] for i in range(n+1)]
	dpp = [[0 for j in range(70)] for i in range(n+1)]

	if s[-1] == "1":
		print(1)
		continue

	for i in range(n):
		ii = -(i+1)
		ss = s[ii]
		i += 1
		aaa = bin(a[ii])[2:]

		for j in range(70):
			dp[i][j] = dp[i-1][j]
			dpp[i][j] = dpp[i-1][j]

		if ss == "1":
			for j in range(len(aaa)-1,-1,-1):
				jj = len(aaa) - 1 - j
				if aaa[j] == "1":
					dp[i][jj] += 1
		else:
			for j in range(len(aaa)-1,-1,-1):
				jj = len(aaa) - 1 - j
				if aaa[j] == "1":
					dpp[i][jj] += 1
	fl = 0
	for i in range(70):
		if dp[-1][i] > dpp[-1][i]:
			fl = 1
	if fl:
		print(1)
	else:
		print(0)

Submission status: Wrong Answer

Solution code:
t = int(input())

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

    for i in range(len(a)):
        if s[i] == '0':
            if bin(ans^a[i]) == 0:
                ans = bin(ans^a[i])
            else:
                if ans == 0:
                    continue
                else:
                    ans = bin(ans^a[i])
        else:          
            if bin(ans^a[i]) != 0:
                ans = bin(ans^a[i])  
            else:
                if ans != 0:
                    continue
                else:
                    ans = bin(ans^a[i])
        ans = int(ans, 0)
    if ans == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
def xor_gauss_jordan(A):
    """掃き出し法でジョルダン標準形を求める"""
    cnt_row = len(A)
    cnt_col = len(bin(max(A))[2::])
 
    rank = 0
    for col in range(cnt_col):
        # ピボットを探す
        pivot = -1
        for row in range(rank, cnt_row):
            if A[row] & 2**(cnt_col - col - 1):
                pivot = row
                break
 
        #  ピボットがない場合は次の列に
        if pivot == -1:
            continue
 
        # 行をスワップする
        A[pivot], A[rank] = A[rank], A[pivot]
 
        # ピボットのある列の値がすべて0になるように掃き出す
        A_rank = A[rank]
        for row in range(cnt_row):
            if row != rank and A[row] & 2**(cnt_col - col - 1):
                A[row] ^= A[rank]
        rank += 1
 
    return A


def compress(string):
    """文字列をランレングス圧縮する
    例) string = "aabccaaabb" -> [(2, a), (1, b), (2, c), (3, a), (2, b)]
    """
    string = string + "#" # 番兵
    n = len(string)
    begin, end, cnt = 0, 1, 1
    ans = []
    while end < n:
        if string[begin] == string[end]:
            end, cnt = end + 1, cnt + 1
        else:
            ans.append((string[begin], cnt))
            begin, end, cnt = end, end + 1, 1
    return ans


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

    s = compress(s)
    r = n
    memo_0 = set()
    flag = False

    for turn, cnt in s[::-1]:
        tmp = xor_gauss_jordan(a[r - cnt:r])
        r -= cnt
        if turn == "1":
            for val in tmp:
                val2 = 0
                for min_ in memo_0:
                    if val & min_ == min_:
                        val2 |= min_
                if val != val2:
                    flag = True
        else:
            for val in tmp:
                memo_0.add(val)

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

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 s[i] == "0":
                    a |= A[i]
                    i += 1
                    if i == n:
                        break
            else:
                while s[i] == "1":
                    b |= A[i]
                    i += 1
                    if i == n:
                        break

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

resolve()

Submission status: Wrong Answer

Solution code:

#testcases = 3
testcases = int(input())
for _ in range(testcases):
         n = int(input())
         a = [int(x) for x in input().split()]
         s = input()
         #n = 2
         #a = [1,2]
         #s = '10'
         regex0 = []
         regex1 = []
         
         if(s[-1] == '1' or s.count('1') > s.count('0')):
             print(1)
             continue
         
         o = []
         z = []
         for i in range(len(a)):
             val = (bin(a[i])[2:])
             val = (60 - len(val))*'0' + val;
             if(s[i]=='0'):
                o.append(val)
             else:
                z.append(val)
         for j in range(60):
             for i in range(len(z)):
                 if(z[i][j] == '1'):
                     regex0.append(('01'))
                     break
             else:
                 regex0.append(('0'))
         for j in range(60):
             for i in range(len(o)):
                 if(o[i][j] == '1'):
                     regex1.append(('01'))
                     break
             else:
                 regex1.append(('0'))
         if(regex0 == regex1):
             print(0)
         else:
             print(1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3


def num2bin(n):
    return tuple(int(d) for d in "{:070b}".format(n))


def can_reach_zero(n, bs, s):
    bins = [num2bin(b) for b in bs]
    max_len = len(bins[0])
    score = [[0 for _ in range(max_len)] for _ in range(2)]
    for i, player in enumerate(s):
        for j, c in enumerate(bins[i]):
            if c == 1:
                score[player][j] += 1
    for player, c in zip(range(2), range(max_len)):
        score[player][c] %= 2
    for s0, s1 in zip(score[0], score[1]):
        if s0 < s1:
            return False
    else:
        return True


def main():
    t = int(input())
    for _ in range(t):
        n = int(input())
        bs = [int(b) for b in input().split()]
        s = [int(d) for d in input()]
        if can_reach_zero(n, bs, s):
            print(0)
        else:
            print(1)


if __name__ == '__main__':
    main()

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):]:
                x ^= a[i]
            elif x ^ a[i] == 0:
                x ^= a[i]
        if s[i] == '1' and x == 0:
            x ^= a[i]
    print(0 if x==0 else 1)

Submission status: Wrong Answer

Solution code:
# N
# A1 A2 ... AN
# S
N = int(input())
for n in range(N):
    print('1')

Submission status: Wrong Answer

Solution code:
from itertools import groupby
from operator import itemgetter


def sweep(l):
    result = set()
    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.add(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)
        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:
t = int(input())
N = []
A = []
S = []
total = []
sum = 0
count = 0
sCount = 0
for i in range(t):
    N.append(int(input()))
    A.append(list(map(int, input().split()))) 
    S.append(input())



for a in A:
    for b in a:
        if S[count][sCount] == "0":
            if sum ^ b == 0:
                continue
            else:
                sum ^= b
        else:
            if sum ^ b == 0:
                sum ^= b
            else:
                continue
        sCount += 1
        # if sum ^ b == 0:
        #     if S[count][sCount] == "0":
        #         sum ^= b
        #     else:
        #         continue
        # else:
        #     if S[count][sCount] == "0":
        #         continue
        #     else:
        #         sum ^= b
        # sCount += 1
    count += 1
    total.append(sum)
    sum = 0
    sCount = 0

for to in total:
    if to == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import math

def main():
    T = int(input())
    for i in range(T):
        N = int(input())
        A = list(map(int, input().split()))
        S = input()
        # print(S,A)
        num0 = set()
        num1 = set()
        digits0 = [0] * 60# 人0の手番のときの各桁の和
        digits1 = [0] * 60# 人1の手番のときの各桁の和
        for j in range(N):
            if S[j] == '0':
                num0.add(A[j])
                for k in range(60):
                    digits0[k] += (A[j] >> k)&1
            else:
                num1.add(A[j])
                for k in range(60):
                    digits1[k] += (A[j] >> k)&1
        
        if len(num0) == 0:
            print(1)
        elif len(num1) == 0:
            print(0)
        elif math.log2(max(num0)+1) < math.log2(max(num1)+1):
            # それぞれのmax(A[i])の対数をとって1の方が大きいと１がかつ
            print(1)
        elif len(num0) < len(num1):# 個数の観点から
            print(1)
        else:
            # 桁の観点から
            flag = True
            # print(num0,digits0)
            # print(num1,digits1)
            for k in range(60):
                if digits0[k] == 0 and digits1[k] > 0:
                    print(1)
                    flag = False
                    break
            if flag:
                print(0)
        
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
t = int(input())

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

    for i in range(len(a)):
        if s[i] == '0':
            if bin(ans^a[i]) == 0:
                continue
            else:
                if ans == 0:
                    continue
                else:
                    ans = bin(ans^a[i])
        else:          
            if bin(ans^a[i]) != 0:
                ans = bin(ans^a[i])  
            else:
                if ans != 0:
                    continue
                else:
                    ans = bin(ans^a[i])
        ans = int(ans, 0)
    if ans == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from sys import setrecursionlimit
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()
    x = 0
    y = 0
    for i in range(n):
        if s[i] == "0":
            y = y|a[i]
        else:
            x = x|a[i]
    b = [(x>>j)&1 for j in range(64)]
    c = [(y>>j)&1 for j in range(64)]
    flag = True
    for k in range(64):
        if b[k]^c[k] == 1:
            print(1)
            flag = False
            break
    if flag:
        print(0)

Submission status: Wrong Answer

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################


for ii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	s = input()
	#we start with x = 0
	x = 0
	for i in range(n):
		if s[i] == "0":
			if x != 0:
				x = x^arr[i]
		else:
			if x==0:
				x = x^arr[i]
			elif arr[i] != x:
				x = x^arr[i]
		#print(i," : ",x)
	if x == 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()
  r=s.rfind("1")
  o=[]
  z=[]
  for i in range(n):
    if s[i]=="0" and i>r:
      z.append(a[i])
    elif s[i]=="1":
      o.append(a[i])
  b=[0]*18
  for i in o:
    for k in range(18):
      if i&(1<<k):b[k]-=1
  for i in z:
    for k in range(18):
      if i&(1<<k):b[k]+=1
  if min(b)<0:print(1)
  else:print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    T = int(_in[0])  # type:int
    initer = 1
    for i in range(T):
        N = int(_in[initer])  # type:int
        A_arr = list(map(int, _in[initer + 1].split(' ')))  # type:list(int)
        S = _in[initer + 2]  # type:str
        initer += 3
        # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
        fin = None
        while len(A_arr) > 0:
            iter_ = 1
            sach = S[-iter_]
            while S[-iter_] == sach:
                iter_ += 1
                if len(S) < iter_:
                    break
            a_arr = A_arr[-iter_+1:]
            del A_arr[-iter_+1:]
            S = S[:-iter_+1]

            flag = [False, False]
            for a in a_arr:
                flag[a%2] = True
                if flag[0] and flag[1]:
                    break
            else:
                if a%2 == 0 and sach == '0':
                    fin = 0
                elif a%2 == 1 and sach == '1':
                    fin = 1
                continue
            print(sach)
            break
        else:
            print('ERROR')
        # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


if __name__ == "__main__":
    main()

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: x % 2, A)) # 0,1で表示
    S = input() # 行動する人
    S = list(S)
    S = [int(s) for s in S] # リスト型数値に変換

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

    print(x)

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:
import sys
sys.setrecursionlimit(10**7)
def dfs(i,p,j):
    if (i,p) in memo:
        return memo[(i,p)]
    if i==N:
        if p==0:
            return 0
        else:
            return 1
    if S[i]=='1':
        res=dfs(i+1,p,j)
        if A[i]>>j&1:
            res=max(res,dfs(i+1,p^1,j))
    if S[i]=='0':
        res=dfs(i+1,p,j)
        if A[i]>>j&1:
            res=min(res,dfs(i+1,p^1,j))
    memo[(i,p)]=res
    return res
        

T=int(input())

for _ in range(T):
    N=int(input())
    A=list(map(int,input().split()))
    S=input()
    bsize=60
    ans=0
    for i in range(bsize):
        memo={}
        ans|=dfs(0,0,i)
    print(ans)

Submission status: Wrong Answer

Solution code:
T=int(input())
N,A,S=[],[],[]
x=0
for _ in range(T):
    N.append(int(input()))
    A.append(list(map(int,input().split())))
    S.append(str(input()))
for i in range(T):
    for j in range(N[i]):
        if S[i][j]=="0":
            if x==0:
                x=0
            else:
                if x^A[i][j]==0:
                    x=0
        elif S[i][j]=="1":
            if x==1:
                x=1
            else:
                if x^A[i][j]==1:
                    x=1
    if x==0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [input() for _ in range(3*n)]
for _ in range(n):
	print(0)

Submission status: Wrong Answer

Solution code:
def base(a, f=False):
    k = 0
    for i in range(64):
        for ind, j in enumerate(a):
            if (j >> i) & 1 == 1:
                break
        else:
            continue

        a[ind], a[k] = a[k], a[ind]
        for ind, j in enumerate(a):
            if ind == k:
                continue
            if (j >> i) & 1 == 1:
                a[ind] ^= a[k]
        k += 1
        if k >= len(a):
            break
    return a[:k]


t = int(input())
for _ in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    s = input()

    b = []
    for i in reversed(range(n)):
        if s[i] == '0':
            b = base(b + [a[i]])

        else:
            c = base(b[:] + [a[i]])
            if len(c) != len(b):
                print(1)
                break

    else:
        print(0)

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:
            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 = input()
x = 0

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

    if x == 0 and A[0] == 1 and A[1] > 1:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:

#testcases = 3
testcases = int(input())
for _ in range(testcases):
         n = int(input())
         a = [int(x) for x in input().split()]
         s = input()
         #n = 2
         #a = [1,2]
         #s = '10'
         regex0 = []
         regex1 = []
         
         if(s[-1] == '1'):
             print(1)
             continue
         
         o = []
         z = []
         for i in range(len(a)):
             val = (bin(a[i])[2:])
             val = (60 - len(val))*'0' + val;
             if(s[i]=='0'):
                o.append(val)
             else:
                z.append(val)
         for j in range(60):
             for i in range(len(z)):
                 if(z[i][j] == '1'):
                     regex0.append(('01'))
                     break
             else:
                 regex0.append(('0'))
         for j in range(60):
             for i in range(len(o)):
                 if(o[i][j] == '1'):
                     regex1.append(('01'))
                     break
             else:
                 regex1.append(('0'))
         if(regex0 == regex1):
             print(0)
         else:
             print(1)