結果
問題 | No.1078 I love Matrix Construction |
ユーザー | gr1msl3y |
提出日時 | 2022-01-27 23:22:59 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,025 bytes |
コンパイル時間 | 495 ms |
コンパイル使用メモリ | 87,240 KB |
実行使用メモリ | 266,320 KB |
最終ジャッジ日時 | 2023-08-27 01:57:24 |
合計ジャッジ時間 | 17,060 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 87 ms
71,568 KB |
testcase_02 | AC | 284 ms
102,696 KB |
testcase_03 | AC | 552 ms
149,100 KB |
testcase_04 | AC | 726 ms
178,312 KB |
testcase_05 | WA | - |
testcase_06 | AC | 297 ms
103,328 KB |
testcase_07 | AC | 212 ms
86,992 KB |
testcase_08 | AC | 595 ms
154,264 KB |
testcase_09 | WA | - |
testcase_10 | AC | 1,360 ms
266,320 KB |
testcase_11 | AC | 786 ms
178,880 KB |
testcase_12 | AC | 1,061 ms
243,976 KB |
testcase_13 | AC | 1,192 ms
264,224 KB |
testcase_14 | AC | 876 ms
206,420 KB |
testcase_15 | AC | 1,129 ms
245,304 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 253 ms
96,256 KB |
testcase_19 | AC | 403 ms
119,248 KB |
testcase_20 | AC | 399 ms
120,056 KB |
testcase_21 | AC | 144 ms
78,948 KB |
ソースコード
from collections import deque, defaultdict def scc(N, G, RG): order = [] seen = [0]*N group = [None]*N def dfs(s): task = deque([(s, 1), (s, 0)]) while task: v, t = task.pop() if t: if seen[v] == 2: continue seen[v] = 2 order.append(v) else: if seen[v]: continue seen[v] = 1 for e in G[v]: if not seen[e]: task.append((e, 1)) task.append((e, 0)) def rdfs(s, col): task = deque([s]) while task: v = task.pop() if seen[v]: continue seen[v] = 1 group[v] = col for e in RG[v]: if not seen[e]: task.append(e) for i in range(N): if not seen[i]: dfs(i) seen = [0]*N label = 0 for s in reversed(order): if not seen[s]: rdfs(s, label) label += 1 return label, group N = int(input()) S = list(map(lambda x: int(x)-1, input().split())) T = list(map(lambda x: int(x)-1, input().split())) U = list(map(int, input().split())) graph = defaultdict(list) rgraph = defaultdict(list) for i in range(N): for j in range(N): s, t, u = S[i], T[i], U[i] x = s*N+j y = j*N+t nx = x+N**2*(u % 2) ny = y+N**2*(u//2) graph[nx].append((ny+N**2) % (2*N**2)) rgraph[(ny+N**2) % (2*N**2)].append(nx) graph[ny].append((nx+N**2) % (2*N**2)) rgraph[(nx+N**2) % (2*N**2)].append(ny) M, sccgraph = scc(2*N**2, graph, rgraph) ans = [[0]*N for _ in range(N)] for i in range(N): for j in range(N): n = i*N+j if sccgraph[n] == sccgraph[n+N**2]: print(-1) exit() elif sccgraph[n] > sccgraph[n+N**2]: ans[i][j] = 1 for a in ans: print(*a)