結果
問題 | No.1605 Matrix Shape |
ユーザー | sepa38 |
提出日時 | 2023-04-16 10:40:03 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,200 bytes |
コンパイル時間 | 431 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 97,792 KB |
最終ジャッジ日時 | 2024-10-11 21:18:56 |
合計ジャッジ時間 | 8,299 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,272 KB |
testcase_01 | AC | 42 ms
53,888 KB |
testcase_02 | AC | 46 ms
53,760 KB |
testcase_03 | AC | 41 ms
53,888 KB |
testcase_04 | WA | - |
testcase_05 | AC | 41 ms
54,016 KB |
testcase_06 | AC | 41 ms
53,760 KB |
testcase_07 | RE | - |
testcase_08 | AC | 43 ms
53,888 KB |
testcase_09 | AC | 43 ms
53,888 KB |
testcase_10 | AC | 42 ms
54,016 KB |
testcase_11 | AC | 42 ms
54,016 KB |
testcase_12 | AC | 42 ms
53,632 KB |
testcase_13 | RE | - |
testcase_14 | AC | 42 ms
53,760 KB |
testcase_15 | AC | 41 ms
54,272 KB |
testcase_16 | AC | 42 ms
54,016 KB |
testcase_17 | AC | 42 ms
53,760 KB |
testcase_18 | AC | 42 ms
53,888 KB |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
ソースコード
import sys sys.setrecursionlimit(500000) def scc(edge): n = len(edge) redge = [[] for i in range(n)] for u in range(n): for v in edge[u]: redge[v].append(u) seen = [0] * n order = [] group = [0] * n def dfs(u): seen[u] = 1 for v in edge[u]: if seen[v] == 0: dfs(v) order.append(u) def rdfs(u, label): seen[u] = 1 group[u] = label for v in redge[u]: if seen[v] == 0: rdfs(v, label) for u in range(n): if seen[u] == 0: dfs(u) seen = [0] * n label = 0 for u in reversed(order): if seen[u] == 0: rdfs(u, label) label += 1 return group from collections import Counter n = int(input()) m = 10 e = [[] for _ in range(m)] ls = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)] ind = [0] * m for h, w in ls: e[h].append(w) ind[w] += 1 g = scc(e) cnt = [0, 0] for i in range(m): if abs(len(e[i]) - ind[i]): if abs(len(e[i]) - ind[i]) > 1: print(0) exit() if len(e[i]) > ind[i]: cnt[0] += 1 else: cnt[1] += 1 if cnt[0] != cnt[1] or max(cnt) > 1: print(0) exit() elif cnt[0]: print(1) else: print(max(Counter(g).values()))