Problem:


Score : 600 points

Problem Statement

Given are an integer N and arrays S, T, U, and V, each of length N.
Construct an N×N matrix a that satisfy the following conditions:

a_{i,j} is an integer.

0 \leq a_{i,j}  \lt 2^{64}.

If S_{i} = 0, the bitwise AND of the elements in the i-th row is U_{i}.

If S_{i} = 1, the bitwise OR of the elements in the i-th row is U_{i}.

If T_{i} = 0, the bitwise AND of the elements in the i-th column is V_{i}.

If T_{i} = 1, the bitwise OR of the elements in the i-th column is V_{i}.

However, there may be cases where no matrix satisfies the conditions.

Constraints

All values in input are integers.

 1 \leq N \leq 500 

 0 \leq S_{i} \leq 1 

 0 \leq T_{i} \leq 1  

 0 \leq U_{i} \lt 2^{64}  

 0 \leq V_{i} \lt 2^{64}  

Input

Input is given from Standard Input in the following format:

N
S_{1} S_{2} ...  S_{N}
T_{1} T_{2} ...  T_{N}
U_{1} U_{2} ...  U_{N}
V_{1} V_{2} ...  V_{N}

Output

If there exists a matrix that satisfies the conditions, print one such matrix in the following format:

a_{1,1} ...  a_{1,N}
:
a_{N,1} ...  a_{N,N}

Note that any matrix satisfying the conditions is accepted.

If no matrix satisfies the conditions, print -1.

Sample Input 1

2
0 1
1 0
1 1
1 0

Sample Output 1

1 1
1 0

In Sample Input 1, we need to find a matrix such that:

the bitwise AND of the elements in the 1-st row is 1;

the bitwise OR of the elements in the 2-nd row is 1;

the bitwise OR of the elements in the 1-st column is 1;

the bitwise AND of the elements in the 2-nd column is 0.

Sample Input 2

2
1 1
1 0
15 15
15 11

Sample Output 2

15 11
15 11



Sample input:
2
0 1
1 0
1 1
1 0


Sample output:
1 1
1 0

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  c = 0
  for i in range(N):
    for j in range(N):
      c += 1
  continue
  
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  ###行のAND=1とOR=0を埋める###
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  ###列のAND=1とOR=0を埋める###
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  ###行と列の値が一致するところを埋める###  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)

  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 1:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 1:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVzerozerolist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  YOKOSUM = [sum(b[i]) for i in range(N)]
  TATESUM = [sum(b[:,i]) for i in range(N)]
  continue
  ###行のOR=1を満たしていく###  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: #まだ満たされてない行を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  ###列のOR=1を満たしていく### 
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: #まだ満たされてない列を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  ###行のAND=1とOR=0を埋める###
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  ###列のAND=1とOR=0を埋める###
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  ###行と列の値が一致するところを埋める###  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)

  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 1:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 1:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVzerozerolist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  YOKOSUM = [sum(b[i]) for i in range(N)]
  TATESUM = [sum(b[:,i]) for i in range(N)]
  continue
  ###行のOR=1を満たしていく###  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: #まだ満たされてない行を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  ###列のOR=1を満たしていく### 
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: #まだ満たされてない列を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  ###行のAND=1とOR=0を埋める###
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  ###列のAND=1とOR=0を埋める###
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  ###行と列の値が一致するところを埋める###  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)

  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 1:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 1:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVzerozerolist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  continue
  ###行のOR=1を満たしていく###  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: #まだ満たされてない行を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  ###列のOR=1を満たしていく### 
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: #まだ満たされてない列を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  ###行のAND=1とOR=0を埋める###
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  ###列のAND=1とOR=0を埋める###
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  ###行と列の値が一致するところを埋める###  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)
  continue
  SUoneonelist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUoneonelist.append(i)
  TVoneonelist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVoneonelist.append(i)
  SUzerozerolist = []
  for i in range(N):
    if S[i] == u[i] == 0:
      SUzerozerolist.append(i)
  TVzerozerolist = []
  for i in range(N):
    if T[i] == v[i] == 0:
      TVzerozerolist.append(i)
  continue
  ###行のOR=1を満たしていく###  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: #まだ満たされてない行を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  ###列のOR=1を満たしていく### 
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: #まだ満たされてない列を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  ###行のAND=1とOR=0を埋める###
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  ###列のAND=1とOR=0を埋める###
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  ###行と列の値が一致するところを埋める###  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)
  
  ###行のOR=1を満たしていく###  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: #まだ満たされてない行を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  
  ###列のOR=1を満たしていく### 
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: #まだ満たされてない列を発見した場合
      pass
      """
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
      """
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.uint64)
T = np.array(list(map(int,input().split())),dtype = np.uint64)
U = np.array(list(map(int,input().split())),dtype = np.uint64)
V = np.array(list(map(int,input().split())),dtype = np.uint64)

ans = np.zeros((N,N),dtype = np.uint64)

for n in range(64):
  u = (U>>n)&1
  v = (V>>n)&1
  invu = np.ones(N,dtype = np.uint64)-u
  invv = np.ones(N,dtype = np.uint64)-v
  b = np.zeros((N,N),dtype = np.uint64)
  check = np.zeros((N,N),dtype = np.uint64)
  ###行のAND=1とOR=0を埋める###
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  ###列のAND=1とOR=0を埋める###
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  ###行と列の値が一致するところを埋める###  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([v]).T,np.ones((1,N),dtype = np.uint64)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),dtype = np.uint64)) & np.dot(np.array([invv]).T,np.ones((1,N),dtype = np.uint64)).T
  b |= same1
  check |= (same1|same0)
  continue
  ###行のOR=1を満たしていく###  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: #まだ満たされてない行を発見した場合
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  
  ###列のOR=1を満たしていく### 
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: #まだ満たされてない列を発見した場合
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  ans += b<<n


for item in ans:
  print(*list(item))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
if N > 100:
  exit()

S = np.array(list(map(int,input().split())),dtype = np.int64)
T = np.array(list(map(int,input().split())),dtype = np.int64)
U = list(map(int,input().split()))
V = list(map(int,input().split()))

Us = []
Vs = []
for n in range(64):
  Us.append([(U[i]>>n)&1 for i in range(N)])
  Vs.append([(V[i]>>n)&1 for i in range(N)])

ans1 = np.zeros((N,N),dtype = np.int64)
ans2 = np.zeros((N,N),dtype = np.int64)

for n in range(64):
  u = np.array(Us[n])
  v = np.array(Vs[n])
  invu = np.ones(N,int)-u
  invv = np.ones(N,int)-v
  b = np.zeros((N,N),int)
  check = np.zeros((N,N),int)
  ###行のAND=1とOR=0を埋める###
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  ###列のAND=1とOR=0を埋める###
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  ###行と列の値が一致するところを埋める###  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),int)) & np.dot(np.array([v]).T,np.ones((1,N),int)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),int)) & np.dot(np.array([invv]).T,np.ones((1,N),int)).T
  b |= same1
  check |= (same1|same0)
  ###行のOR=1を満たしていく###  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: #まだ満たされてない行を発見した場合
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  
  ###列のOR=1を満たしていく### 
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: #まだ満たされてない列を発見した場合
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  if n<32:
    ans1 += b<<n
  else:
    ans2 += b<<(n-32)

ans = [[int(ans1[i][j])+(int(ans2[i][j])<<32) for j in range(N)] for i in range(N)]
for item in ans:
  print(*list(item))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

S = np.array(list(map(int,input().split())),dtype = np.int64)
T = np.array(list(map(int,input().split())),dtype = np.int64)
U = list(map(int,input().split()))
V = list(map(int,input().split()))

Us = []
Vs = []
for n in range(64):
  Us.append([(U[i]>>n)&1 for i in range(N)])
  Vs.append([(V[i]>>n)&1 for i in range(N)])

ans1 = np.zeros((N,N),dtype = np.int64)
ans2 = np.zeros((N,N),dtype = np.int64)

for n in range(64):
  u = np.array(Us[n])
  v = np.array(Vs[n])
  invu = np.ones(N,int)-u
  invv = np.ones(N,int)-v
  b = np.zeros((N,N),int)
  check = np.zeros((N,N),int)
  ###行のAND=1とOR=0を埋める###
  for i in range(N):
    if S[i] != u[i]:
      if u[i] == 1:
        b[i] = np.ones(N,int)
      check[i] = np.ones(N,int)
  ###列のAND=1とOR=0を埋める###
  for i in range(N):
    if T[i] != v[i]:
      if v[i] == 1:
        if max(b[:,i]^check[:,i])!=0:
          print(-1)
          exit()
        b[:,i] = np.ones(N,int)
      if v[i] == 0:
        if max(b[:,i])!=0:
          print(-1)
          exit()
      check[:,i] = np.ones((1,N),int)
  ###行と列の値が一致するところを埋める###  
  same1 = np.dot(np.array([u]).T,np.ones((1,N),int)) & np.dot(np.array([v]).T,np.ones((1,N),int)).T
  same0 = np.dot(np.array([invu]).T,np.ones((1,N),int)) & np.dot(np.array([invv]).T,np.ones((1,N),int)).T
  b |= same1
  check |= (same1|same0)
  ###行のOR=1を満たしていく###  
  for i in range(N):
    if S[i] == u[i] == 1 and max(b[i]) == 0: #まだ満たされてない行を発見した場合
      flag = 0 #未解決
      for j in range(N):
        if T[j] == v[j] == b[i][j] == check[i][j] == 0 and sum(b[:,j]) < N-1:
          b[i][j] = check[i][j] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  
  ###列のOR=1を満たしていく### 
  for i in range(N):
    if T[i] == v[i] == 1 and max(b[:,i]) == 0: #まだ満たされてない列を発見した場合
      flag = 0 #未解決
      for j in range(N):
        if S[j] == u[j] == b[j][i] == check[j][i] == 0 and sum(b[j]) < N-1:
          b[j][i] = check[j][i] = flag = 1
          break
      if not flag:
        print(-1)
        exit()
  """
  for i in range(N):
    if S[i] == 0 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] == mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 0 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] != mask_gyo[i]:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 0:
      if b & mask_gyo[i] != 0:
        print(-1)
        exit()
    if S[i] == 1 and((u>>i) & 1) == 1:
      if b & mask_gyo[i] == 0:
        print(-1)
        exit()
  
  for i in range(N):
    if T[i] == 0 and((v>>i) & 1) == 0:
      if b & mask_retu[i] == mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 0 and((v>>i) & 1) == 1:
      if b & mask_retu[i] != mask_retu[i]:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 0:
      if b & mask_retu[i] != 0:
        print(-1)
        exit()
    if T[i] == 1 and((v>>i) & 1) == 1:
      if b & mask_retu[i] == 0:
        print(-1)
        exit()
  """
  if n<32:
    ans1 += b<<n
  else:
    ans2 += b<<(n-32)

ans = [[int(ans1[i][j])+(int(ans2[i][j])<<32) for j in range(N)] for i in range(N)]
for item in ans:
  print(*list(item))

Submission status: Wrong Answer

Solution code:
N=int(input())
slist=list(map(int,input().split()))
tlist=list(map(int,input().split()))
ulist=list(map(int,input().split()))
vlist=list(map(int,input().split()))

max_digit=4
amat=[[[-1]*max_digit for _ in range(N)] for _ in range(N)]

for i in range(N):
  s=slist[i]
  u=ulist[i]
  if s==0:
    for k in range(max_digit):
      u1=u&1
      if u1==1:
        for j in range(N):
          amat[i][j][-1-k]=1
      u>>=1      
  else:
    for k in range(max_digit):
      u1=u&1
      if u1==0:
        for j in range(N):
          amat[i][j][-1-k]=0
      u>>=1
      
  t=tlist[i]
  v=vlist[i]
  if t==0:
    for k in range(max_digit):
      v1=v&1
      if v1==1:
        for j in range(N):
          amat[j][i][-1-k]=1
      v>>=1
  else:
    for k in range(max_digit):
      v1=v&1
      if v1==0:
        for j in range(N):
          amat[j][i][-1-k]=0
      v>>=1
      
for i in range(N):
  for j in range(N):
    u=ulist[i]
    v=vlist[j]
    for k in range(max_digit):
      u1=u&1
      v1=v&1
      if u1==v1:
        amat[i][j][-1-k]=u1
      u>>=1
      v>>=1      
#print(amat)

for i in range(N):
  for j in range(N):
    s=slist[i]
    t=tlist[j]
    u=ulist[i]
    v=vlist[j]
    for k in range(max_digit):
      u1=u&1
      v1=v&1
      if amat[i][j][-1-k]==-1:
        if s==1 and u1==1:
          if t==0: #v1==0
            amat[i][j][-1-k]=0
          else:
            amat[i][j][-1-k]=1
        elif t==1 and v1==1:
          if s==0: #u1==0
            amat[i][j][-1-k]=0
          else:
            amat[i][j][-1-k]=1
#print(amat)

answer_mat=[[0]*N for _ in range(N)]
for i in range(N):
  for j in range(N):
    ans=0
    base=1
    a=amat[i][j]
    for k in range(max_digit):
      ans+=a[-1-k]*base
      base<<=1
    
    answer_mat[i][j]=ans
    
#print(answer_mat)
for i in range(N):
  print(*answer_mat[i])