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 numpy as np
t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    s = input()
    lsa = np.zeros((200,62))
    if s[-1] == "1":
        print(1)
        continue
    for i in range(n-1,-1,-1):
        b = format(a[i], '062b')
        # print(i,s[i])
        if s[i] == "0":
            for j in range(62):
                lsa[i][j] = int(b[j])
            if s[i-1] == "1":
                ra = np.linalg.matrix_rank(lsa)
                # print("ra=",ra)
        else:
            for j in range(62):
                lsa[i][j] = int(b[j])
            rb = np.linalg.matrix_rank(lsa)
            # print("rb=",rb)
            if rb != ra:
                print(1)
                break
    else:
        print(0)
    # print(lsa[0:6])

Submission status: Wrong Answer

Solution code:
ans = []
for _ in range(int(input())):
    x = 0
    n = int(input())
    a = list(map(int, input().split()))
    s = str(input())

    def f(i, x):
        if i == n - 1:
            return x == 0
        if f(i + 1, x):
            return True
        if f(i + 1, x ^ a[i]):
            return True
        return False

    if f(0, 0):
        ans.append(0)
    else:
        ans.append(1)
    
for j in ans:
    print(j)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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+1
          break
  if x == 0:
    return True
  else:
    return False
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)
            for k in range(i)[::-1]:
              if mat[j]&1<<k and k in pivot:
                for l in range(j+1,len(mat)):
                  if mat[l]&1<<k:
                    mat[j] ^= mat[l]
            break
        else:
          mat.append(x)
        break
t = int(input())
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()
        break
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
t=int(input())
def solve():
    n=int(input())
    a=[int(_) for _ in input().split()]
    s=input()

    a0=["0"*60]
    a1=["0"*60]
    for i in range(n):
        if s[i]=='0':
            _s=bin(a[i])[2:]
            a0.append("0"*(60-len(_s))+_s)
        else:
            _s=bin(a[i])[2:]
            a1.append("0"*(60-len(_s))+_s)
    for i in range(60):
        for j in range(i+1,60):
            t0,t1=0,0
            for k in range(len(a0)):
                for l in range(i+1,len(a0)):
                    c1,c2=a0[k][i],a0[l][j]
                    if c1!=c2:
                        t0=2
                        break
                    elif c1=='1':
                        t0=1
                else:
                    continue
                break
            for k in range(len(a1)):
                for l in range(i+1,len(a1)):
                    c1,c2=a1[k][i],a1[l][j]
                    if c1!=c2:
                        t1=2
                        break
                    elif c1=='1':
                        t1=1
                else:
                    continue
                break
            if t0<t1:
                return "1"

    return "0"

for _ in range(t):
    print(solve())

Submission status: Wrong Answer

Solution code:

def test(n,a,s):
    x = 0
    player = 0
    for iround in range(n):
        player = int(s[iround])
        ai = a[iround]%2
        if player == 0:
            if x % 2 == 1 and ai == 1:
                x = x ^ a[i]           
        else:
            if x % 2 == 0 and ai == 1:
                x =  x ^ a[i]
    print(x%2)

t = int(input())
n = []
a = []
s = []
for i in range(t):
    n.append(int(input()))
    a.append(list(map(int,input().split())))
    s.append(input())


for i in range(t):
    test(n[i],a[i],s[i])

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)
    all_li = []
    tmp = []
    now = ''
    for i, (a,s) in enumerate(zip(a_li,s_li)):
        if i == 0:
            now = s
            tmp.append(a)
        else:
            if s == now:
                tmp.append(a)
            else:
                all_li.append([now,tmp])
                now = s
                tmp = [a]
    all_li.append([now,tmp])
    #print(all_li)
    #[['1', [2, 3, 4]], ['0', [5, 6, 7]]]
    x = 0
    for al in all_li:
        kumi = al[0]
        kouho = al[1]
        if kumi == '1':
            for kou in kouho:
                if x == 0:
                    x = x^kou
        else:
            if x != 0:
                xor_li = []
                for zen in kouho:
                    xor_li.append(x^zen)
                if 0 in xor_li:
                    x = 0
                while len(kouho)>0:
                    if x == 0:
                        break
                    pp = kouho.pop(0)
                    #print(pp,'pp')
                    tt = x^pp
                    #print(tt,kouho,'tt','kouho')
                    kkk_li = []
                    for kkk in kouho:
                        kkk_li.append(tt^kkk)
                    if 0 in kkk_li:
                        x = 0
                        break
                    else:
                        x = tt
    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()
    hito0=[0]*60
    hito1=[0]*60
    for i in range(N):
        if S[i]=="0":
            a=A[i]
            for j in range(60):
                if a<=0:
                    break
                b=a%2
                a//=2
                hito0[j]+=b
        else:
            a=A[i]
            for j in range(60):
                if a<=0:
                    break
                b=a%2
                a//=2
                hito1[j]+=b
    ans=True
    for i in range(60):
        if hito0[i]==0 and hito1[i]>=1:
            ans=False
    if ans:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

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

  for i in range(N):
#    print(S[i], A[i], x)
    if S[i] == '0':
      if x == 0:
        continue
      else:
        x = x ^ A[i]
    else:
      xx = x ^ A[i]
      if xx != 0:
        x = xx
      else:
        if i == (N-1):
          if x != 0:
            x = xx
        continue        
#    print(x)
  if x == 0:
    print(0)
  else:
    print(1)

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    s=str(input())
    if not 1 in a:
        print(0)
    else:
        for j in range(n):
            if a[-1-j]%2==1:
                print(int(s[-1-j]))
                break

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

def standard_form(A):
    for k in range(60,-1,-1):
        bit = 1<<k
        exists = A&bit==bit
        used = A>2*bit
        i = np.where(exists & ~used)[0]
        if len(i) == 0:
            continue
        i = i[0]
        x = A[i]
        A[exists] ^= x
        A[i] = x
    return A



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

    task = set([0])

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


    q = []
    win = "0"
    for i in range(n-1, -1, -1):
        if now == "0":
            if s[i] == "0":
                q.append(a[i])
            else:
                q = standard_form(np.array(q, np.int64))
                task = task | set(q)
                task = standard_form(np.array(list(task), np.int64))
                task = set(task)
                q = [a[i]]
                now = "1"
        else:
            if s[i] == "1":
                q.append(a[i])
            else:
                q = standard_form(np.array(q, np.int64))
                if task != task | set(q):
                    win = "1"
                    break

                q = [a[i]]
                now = "0"

    if now == "1":
        q = standard_form(np.array(q, np.int64))
        if task != task | set(q):
            win = "1"

    print(win)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
t=int(input())
def split(word): 
    return [char for char in word] 
for _ in range(t):
  n=int(input())
  a=list(map(int,input().split()))
  s=str(input())
  finalsay=[]
  for i in range(n):
    finalsay.append([])
  m=[]
  for i in range(n):
    k=split('{0:b}'.format(a[i]))
    k.reverse()
    for j in range(70-len(k)):
      k.append('0')
    k.reverse()
    m.append(k)
  finallist=[-1]*70
  for i in range(70):
    for j in range(n):
      if m[n-1-j][i]=='1':
        finallist[i]=n-1-j
        break
  failflag=0
  for i in range(70):
    if finallist[i]==-1:
      continue
    if s[finallist[i]]=='1':
      failflag=1
      break
    else:
      finalsay[finallist[i]].append(i)
  if failflag==1:
    print(1)
    continue
  zerolist=[]
  for i in range(n):
    A=finalsay[i]
    r=len(A)
    if r<=1:
      continue
    for j in range(0,r-1):
      for k in range(j+1,r):
        opt1=A[j]
        opt2=A[k]
        for p in range(70):
          if m[i][p]=='1':
            continue
          for l in range(n):
            if (int(m[n-1-l][opt1])+int(m[n-1-l][opt2])+int(m[n-1-l][p]))%2!=0:
              if s[n-1-l]=='1':
                failflag=1
              break
            if failflag==1:
              break
        if failflag==1:
          break
      if failflag==1:
        break
    if failflag==1:
      break
  if failflag==1:
    print(1)
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
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
  if x == 0:
    return True
  else:
    return False
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)
            for k in range(i)[::-1]:
              if mat[j]&1<<k and k in pivot:
                for l in range(j+1,len(mat)):
                  if mat[l]&1<<k:
                    mat[j] ^= mat[l]
            break
        else:
          mat.append(x)
        break
t = int(input())
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())


for _ in range(t):
    n = int(input())
    *a, = map(int, input().split())
    s = input()
    o = 0
    p = 0

    for i in range(n):
        if s[i] == "1":
            o |= a[i]
        else:
            p |= a[i]

    if o ^ p:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
def popcount(x):
    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f  # 8bitごと
    x = x + (x >> 8)  # 16bitごと
    x = x + (x >> 16)  # 32bitごと
    x = x + (x >> 32)  # 64bitごと = 全部の合計
    return x & 0x0000007f


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

        # 人１がビットを最後に立てた後に０にできるなら０にならない
        L = max(A).bit_length()
        if S[-1] == '1':
            print(1)
        else:
            cur = 0
            ss = [[0, 0] for i in range(N+1)]
            for i in range(N-1, -1, -1):
                if S[i] == '0':
                    ss[i][0] = ss[i+1][0] | A[i]
                    ss[i][1] = ss[i+1][1]
                else:
                    ss[i][1] = ss[i+1][1] | A[i]
                    ss[i][0] = ss[i+1][0]

            for i in range(N):
                k = int(S[i])
                tmp = ss[i+1]

                for j in range(L):
                    if (A[i] >> j) % 2:
                        if k == 1:
                            if (cur >> j) % 2 == 0 and((tmp[0] >> j) % 2 == 0):
                                cur ^= A[i]
                                break
                        else:
                            if (cur >> j) % 2 and ((tmp[1] >> j) % 2 == 0):
                                cur ^= A[i]
                                break
                    if j == L-1:
                        tmp = cur ^ A[i]
                        if k:
                            if popcount(tmp) > popcount(cur):
                                cur = tmp
                        else:
                            if popcount(tmp) < popcount(cur):
                                cur = tmp

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


main()

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
T=int(input())
for i in range(T):
    N=int(input())
    A=list(map(int,input().split()))
    S=input()
    l=[1]*60
    c0=c1=0
    t=0
    for j in range(N-1,-1,-1):
        if S[j]=="0":
            c0+=1
            for k in range(60):
                if (A[j]>>k)%2:
                    l[k]=0
        else:
            c1+=1
            if c1>c0:
                t=1
                break
            for k in range(60):
                if (A[j]>>k)%2 and l[k]:
                    t=1
                    break
            else:
                continue
            break
    print(t)

Submission status: Wrong Answer

Solution code:
def popcount(x):
    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f  # 8bitごと
    x = x + (x >> 8)  # 16bitごと
    x = x + (x >> 16)  # 32bitごと
    x = x + (x >> 32)  # 64bitごと = 全部の合計
    return x & 0x0000007f


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

        # 人１がビットを最後に立てた後に０にできるなら０にならない
        L = max(A).bit_length()
        if S[-1] == '1':
            print(1)
        else:
            cur = 0
            ss = [[0, 0] for i in range(N+1)]
            for i in range(N-1, -1, -1):
                if S[i] == '0':
                    ss[i][0] = ss[i+1][0] | A[i]
                    ss[i][1] = ss[i+1][1]
                else:
                    ss[i][1] = ss[i+1][1] | A[i]
                    ss[i][0] = ss[i+1][0]

            for i in range(N):
                k = int(S[i])
                tmp = ss[i+1]

                for j in range(L):
                    if (A[i] >> j) % 2:
                        if k == 1:
                            if (cur >> j) % 2 == 0 and((tmp[0] >> j) % 2 == 0):
                                cur ^= A[i]
                                break
                        else:
                            if (cur >> j) % 2 and ((tmp[1] >> j) % 2 == 0):
                                cur ^= A[i]
                                break
                    if j == L-1:
                        tmp = cur ^ A[i]
                        if k:
                            if popcount(tmp) >= popcount(cur):
                                cur = tmp
                        else:
                            if popcount(tmp) < popcount(cur):
                                cur = tmp

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


main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
import collections

T = int(input())
for i in range(T):
    x = 0
    L0 = [0]
    L1 = [0]
    #print("x:", x)
    N = int(input())
    A = list(map(int, input().split()))
    S = input()
    if S.count('0') < N / 2:
        for i, s in enumerate(S):
            if s == "0":
                for l0 in L0:
                    tmp = l0 ^ A[i]
                    if tmp not in L0:
                        L0.append(tmp)
        for i, s in enumerate(S):
            if s == "1":
                for l1 in L1:
                    tmp = l1 ^ A[i]
                    if tmp not in L1:
                        L1.append(tmp)
            if set(L0) <= set(L1):
                print(0)
                break
    else:
        for i, s in enumerate(S):
            if s == "1":
                for l1 in L1:
                    tmp = l1 ^ A[i]
                    if tmp not in L1:
                        L1.append(tmp)
        for i, s in enumerate(S):
            if s == "0":
                for l0 in L0:
                    tmp = l0 ^ A[i]
                    if tmp not in L0:
                        L0.append(tmp)
            if not set(L0) <= set(L1):
                print(1)
                break

    if set(L0) <= set(L1):
        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]
    U = [set(), set()]
    for s, a in zip(S, A):
        if s == "0":
            P[0] |= int(a)
            U[0].add(a)
        elif s == "1":
            P[1] |= int(a)
            U[1].add(a)
        else:
            raise ValueError()
    if len(U[0]) < bin(P[0]).count("1"):
        return 1
    while P[0] > 0 or P[1] > 0:
        if P[1] & 1 == 1 and P[0] & 1 == 0:
            return 1
        P[0] >>= 1
        P[1] >>= 1
    return 0


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:
lineNum = int(input())
lines = []
for i in range(3 * lineNum):
    lines.append(input())
changeables = []
for i in range(lineNum):
    start = 3 * i
    end = 3 * (i + 1)
    case = lines[start:end]
    nums = case[1].split()
    persons = case[2]
    for i in range(int(case[0])):
        person = int(persons[i])
        num = int(nums[i])
        if num % 2 == 1:
            changeables.append(person)
    else:
        print(changeables[-1])

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):
        if s[i] == 1:
            if res == a[i]:
                continue
            else:
                res ^= a[i]
        if s[i] == 0:
            if res == a[i]:
                res ^= a[i]
            else:
                continue
    if res != 0:
        print("1")
    else:
        print("0")

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

Submission status: Wrong Answer

Solution code:
def popcount(x):
    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f  # 8bitごと
    x = x + (x >> 8)  # 16bitごと
    x = x + (x >> 16)  # 32bitごと
    x = x + (x >> 32)  # 64bitごと = 全部の合計
    return x & 0x0000007f


def main():
    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()
        cur = 0
        for i in range(N):
            tmp = cur ^ A[i]
            k = int(S[i])
            if k:
                if popcount(tmp) >= popcount(cur):
                    cur = tmp
            else:
                if popcount(tmp) < popcount(cur):
                    cur = tmp

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


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()
        
        for j in range(N):
            if S[j] == '0':
                num0.add(A[j])
            else:
                num1.add(A[j])
        
        if len(num0) == 0:
            print(1)
        elif len(num1) == 0:
            print(0)
        else:
            digits0 = math.ceil(math.log2(max(num0)+1))
            digits1 = math.ceil(math.log2(max(num1)+1))
            if digits0 < digits1:
                # それぞれのmax(A[i])の対数をとって1の方が大きいと１がかつ
                print(1)
            else:
                if len(num0) < digits0:# 2^digits0の空間を充足できない
                    if num0 == num1:
                        print(0)
                    else:
                        print(1)
                else:# 1,0のベクトルが線型独立か調べる
                    # 各桁のベクトルを保持する
                    vector0 = [[0] * len(num0) for _ in range(digits0)]
                    for i,n in enumerate(num0):
                        for d in range(digits0):
                            vector0[d][i] =  (n >> d) & 1
                    iso_num0 = [0] * digits0
                    for i in range(digits0):
                        iso_num0[i] = sum(vector0[i])

                    vector1 = [[0] * len(num1) for _ in range(digits1)]
                    for i,n in enumerate(num1):
                        for d in range(digits1):
                            vector1[d][i] =  (n >> d) & 1
                    iso_num1 = [0] * digits1
                    for i in range(digits1):
                        iso_num1[i] = sum(vector1[i])
                    
                    # print(vector0,vector1)
                    # print(iso_num0,digits0)
                    # print(iso_num1,digits1)
                    flag = True
                    for i in range(digits1):
                        if iso_num1[i] > 0 and iso_num0[i] == 0:
                            flag = False
                            break
                    if flag:
                        print(0)
                    else:
                        print(1)
        
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
t = int(input())
l = [list(map(int,input().split())) for _ in range(t*3)]

ans=[]
n = []
a = []
s = []
#n,a,sに代入
for i in range(t*3):
    if i%3==0:
        n.append(l[i]) 
    if i%3==1:
        a.append(l[i]) 
    if i%3==2: # ｓに代入しつつ文字列に置き換え
        s.append(l[i])
for m in range(t):
    for j in range(n[m][0]):
        if j==0:
            x = a[0][0]
        if j>0:
            x =a[m][j] ^ x
    ans = format(x, 'b')
    if ans[-1]=="0":
        print("0")
    if ans[-1]!="0":
        print("1")

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
def main():
    T = int(input())
    for _ in range(T):
        N = int(input())
        A = [int(i) for i in input().split()]
        S = list(input())
        ans = 0
        for i in range(N-1):
            if S[i] == '0':   
                flag = False
                a = ans ^ A[i]
                for j in range(i+1, N):
                    if S[j] == '0' and a ^ A[j] == 0:
                        flag = True
                        break
                if flag:
                    ans = ans ^ A[i]
            else:
                flag = False
                a = ans ^ A[i]
                for j in range(i+1, N):
                    if S[j] == '0' and a ^ A[j] == 0:
                        flag = True
                        break
                if not flag:
                    ans = ans ^ A[i]
        if S[-1] == '1' and ans == 0:
            ans = ans ^ A[-1]
        elif S[-1] =='0' and ans != 0:
            ans = ans ^ A[-1]
        if ans == 0:
            print('0')
        else:
            print('1')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    def sweep(arr):
        col = max(arr).bit_length()
        row = len(arr)

        rank = 0
        for c in range(col):
            piv = -1
            for r in range(c, row):
                if arr[r] >> c & 1:
                    piv = r
            if piv == -1:
                continue

            arr[piv], arr[rank] = arr[rank], arr[piv]

            for r in range(row):
                if r == rank:
                    continue
                if arr[r] >> c & 1:
                    arr[r] ^= arr[rank]

            rank += 1

        return set(arr)

    def solve():
        N = int(input())
        A = list(map(int, input().split()))[::-1]
        S = input()[::-1]
        B0 = set()

        pre = '-1'
        left = 0
        for i, s in enumerate(S):
            if s != pre and i != 0:
                if s == '0':
                    B1 = sweep(A[left:i])
                    for b1 in B1:
                        for b0 in B0:
                            if b1 & b0 == b0:
                                b1 ^= b0
                        if b1:
                            return 1
                else:
                    B0 = sweep(A[left:i] + list(B0))

                left = i

            pre = s

        if pre == '1':
            B1 = sweep(A[left:])
            for b1 in B1:
                for b0 in B0:
                    if b1 & b0:
                        b1 ^= b0
                if b1:
                    return 1

        return 0

    for _ in [0]*int(input()):
        print(solve())

if __name__ == '__main__':
    main()

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':
            if arr[3] != bin(0) or 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:
            if arr[3] == bin(0) or bin(int(arr[3], 2) ^ int(arr[1][i])) != bin(0):
                arr[3] = bin(int(arr[3], 2) ^ int(arr[1][i]))
            elif bin(int(arr[3], 2) ^ int(arr[1][i])) != bin(0) and len(arr[1]) != i+1 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_li = list(map(int,input().split()))
    s_li = list(input())
    #print(s_li)
    all_li = []
    tmp = []
    now = ''
    for i, (a,s) in enumerate(zip(a_li,s_li)):
        if i == 0:
            now = s
            tmp.append(a)
        else:
            if s == now:
                tmp.append(a)
            else:
                all_li.append([now,tmp])
                now = s
                tmp = [a]
    all_li.append([now,tmp])
    #print(all_li)
    #[['1', [2, 3, 4]], ['0', [5, 6, 7]]]
    x = 0
    for al in all_li:
        kumi = al[0]
        kouho = al[1]
        if kumi == '1':
            for kou in kouho:
                if x == 0:
                    x = x^kou
        else:
            if x != 0:
                while len(kouho)>0:
                    if x == 0:
                        break
                    pp = kouho.pop(0)
                    #print(pp,'pp')
                    tt = x^pp
                    #print(tt,kouho,'tt','kouho')
                    kkk_li = []
                    for kkk in kouho:
                        kkk_li.append(tt^kkk)
                    if 0 in kkk_li:
                        x = 0
                        break
                    else:
                        x = tt
    if x == 0:
        print(0)
    else:
        print(1)