結果
| 問題 |
No.1078 I love Matrix Construction
|
| コンテスト | |
| ユーザー |
Salmonize
|
| 提出日時 | 2020-06-12 22:17:17 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,703 bytes |
| コンパイル時間 | 129 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 159,760 KB |
| 最終ジャッジ日時 | 2024-06-24 05:12:39 |
| 合計ジャッジ時間 | 18,929 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 5 TLE * 1 |
ソースコード
import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
def SCC(N, G, RG):
order = []
used = [0]*N
group = [None]*N
def dfs(s):
used[s] = 1
for t in G[s]:
if not used[t]:
dfs(t)
order.append(s)
def rdfs(s, col):
group[s] = col
used[s] = 1
for t in RG[s]:
if not used[t]:
rdfs(t, col)
for i in range(N):
if not used[i]:
dfs(i)
used = [0]*N
label = 0
for s in reversed(order):
if not used[s]:
rdfs(s, label)
label += 1
return label, group
def solve():
n = ni()
s = [x-1 for x in nl()]
t = [x-1 for x in nl()]
u = nl()
m = 2 * n ** 2
G = [list() for _ in range(m)]
rG = [list() for _ in range(m)]
for i in range(n):
cs, ct, cu = s[i], t[i], u[i]
for j in range(n):
x = [cs * n + j, cs * n + j + n**2]
y = [j * n + ct, j * n + ct + n**2]
G[x[cu & 1]].append(y[(cu >> 1) ^ 1])
rG[y[(cu >> 1) ^ 1]].append(x[cu & 1])
G[y[cu >> 1]].append(x[cu & 1 ^ 1])
rG[x[cu & 1 ^ 1]].append(y[cu >> 1])
_, gr = SCC(m, G, rG)
ret = [0]*n**2
for i in range(n**2):
if gr[i] == gr[i+n**2]:
print(-1)
return
ret[i] = int(gr[i] > gr[i+n**2])
for i in range(n):
print(*ret[i*n:(i+1)*n])
return
solve()
Salmonize