結果
問題 | No.1078 I love Matrix Construction |
ユーザー | gr1msl3y |
提出日時 | 2022-01-28 00:10:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,729 ms / 2,000 ms |
コード長 | 2,025 bytes |
コンパイル時間 | 399 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 268,308 KB |
最終ジャッジ日時 | 2024-12-26 09:10:08 |
合計ジャッジ時間 | 17,821 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
54,144 KB |
testcase_01 | AC | 56 ms
54,144 KB |
testcase_02 | AC | 352 ms
102,320 KB |
testcase_03 | AC | 633 ms
148,472 KB |
testcase_04 | AC | 863 ms
178,344 KB |
testcase_05 | AC | 750 ms
158,032 KB |
testcase_06 | AC | 316 ms
103,132 KB |
testcase_07 | AC | 225 ms
85,844 KB |
testcase_08 | AC | 707 ms
157,640 KB |
testcase_09 | AC | 213 ms
80,128 KB |
testcase_10 | AC | 1,729 ms
264,676 KB |
testcase_11 | AC | 920 ms
175,956 KB |
testcase_12 | AC | 1,297 ms
241,972 KB |
testcase_13 | AC | 1,475 ms
268,308 KB |
testcase_14 | AC | 984 ms
202,684 KB |
testcase_15 | AC | 1,347 ms
247,776 KB |
testcase_16 | AC | 220 ms
83,632 KB |
testcase_17 | AC | 57 ms
54,016 KB |
testcase_18 | AC | 284 ms
94,160 KB |
testcase_19 | AC | 457 ms
117,900 KB |
testcase_20 | AC | 442 ms
117,996 KB |
testcase_21 | AC | 145 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)