結果
問題 | No.1078 I love Matrix Construction |
ユーザー | gr1msl3y |
提出日時 | 2022-01-28 00:10:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,315 ms / 2,000 ms |
コード長 | 2,025 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 82,352 KB |
実行使用メモリ | 268,436 KB |
最終ジャッジ日時 | 2024-06-07 22:46:38 |
合計ジャッジ時間 | 13,107 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,144 KB |
testcase_01 | AC | 41 ms
53,888 KB |
testcase_02 | AC | 252 ms
102,448 KB |
testcase_03 | AC | 487 ms
148,348 KB |
testcase_04 | AC | 656 ms
178,472 KB |
testcase_05 | AC | 567 ms
158,664 KB |
testcase_06 | AC | 242 ms
103,008 KB |
testcase_07 | AC | 162 ms
85,972 KB |
testcase_08 | AC | 551 ms
157,744 KB |
testcase_09 | AC | 147 ms
80,256 KB |
testcase_10 | AC | 1,315 ms
265,024 KB |
testcase_11 | AC | 679 ms
176,348 KB |
testcase_12 | AC | 1,003 ms
241,776 KB |
testcase_13 | AC | 1,226 ms
268,436 KB |
testcase_14 | AC | 794 ms
203,092 KB |
testcase_15 | AC | 1,063 ms
247,912 KB |
testcase_16 | AC | 155 ms
84,016 KB |
testcase_17 | AC | 41 ms
54,272 KB |
testcase_18 | AC | 201 ms
94,328 KB |
testcase_19 | AC | 337 ms
117,776 KB |
testcase_20 | AC | 328 ms
118,004 KB |
testcase_21 | AC | 107 ms
77,824 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)