結果
問題 | No.1605 Matrix Shape |
ユーザー | trineutron |
提出日時 | 2021-07-16 21:57:55 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,303 ms / 2,000 ms |
コード長 | 976 bytes |
コンパイル時間 | 507 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 23,424 KB |
最終ジャッジ日時 | 2024-07-06 09:05:56 |
合計ジャッジ時間 | 23,204 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 166 ms
23,168 KB |
testcase_01 | AC | 165 ms
23,168 KB |
testcase_02 | AC | 58 ms
23,296 KB |
testcase_03 | AC | 164 ms
23,168 KB |
testcase_04 | AC | 58 ms
23,168 KB |
testcase_05 | AC | 170 ms
23,168 KB |
testcase_06 | AC | 163 ms
23,296 KB |
testcase_07 | AC | 59 ms
23,168 KB |
testcase_08 | AC | 162 ms
23,168 KB |
testcase_09 | AC | 169 ms
23,168 KB |
testcase_10 | AC | 169 ms
23,168 KB |
testcase_11 | AC | 90 ms
23,296 KB |
testcase_12 | AC | 168 ms
23,168 KB |
testcase_13 | AC | 167 ms
23,168 KB |
testcase_14 | AC | 174 ms
23,168 KB |
testcase_15 | AC | 175 ms
23,296 KB |
testcase_16 | AC | 168 ms
23,424 KB |
testcase_17 | AC | 92 ms
23,168 KB |
testcase_18 | AC | 91 ms
23,296 KB |
testcase_19 | AC | 1,287 ms
23,168 KB |
testcase_20 | AC | 1,167 ms
23,168 KB |
testcase_21 | AC | 1,130 ms
23,296 KB |
testcase_22 | AC | 1,109 ms
23,168 KB |
testcase_23 | AC | 1,266 ms
23,168 KB |
testcase_24 | AC | 1,303 ms
23,168 KB |
testcase_25 | AC | 933 ms
23,168 KB |
testcase_26 | AC | 942 ms
23,168 KB |
testcase_27 | AC | 936 ms
23,296 KB |
testcase_28 | AC | 829 ms
23,296 KB |
testcase_29 | AC | 946 ms
23,168 KB |
testcase_30 | AC | 1,114 ms
23,168 KB |
testcase_31 | AC | 1,122 ms
23,296 KB |
testcase_32 | AC | 1,007 ms
23,168 KB |
testcase_33 | AC | 897 ms
23,168 KB |
testcase_34 | AC | 878 ms
23,168 KB |
testcase_35 | AC | 993 ms
23,168 KB |
testcase_36 | AC | 590 ms
23,168 KB |
ソースコード
n = int(input()) par = [i for i in range(200000)] sz = [1] * 200000 def find(k): if par[k] == k: return k par[k] = find(par[k]) return par[k] def merge(k, l): k = find(k) l = find(l) if k == l: return if sz[k] > sz[l]: k, l = l, k par[k] = l sz[l] += sz[k] count_h = [0] * 200000 count_w = [0] * 200000 for i in range(n): h, w = map(int, input().split()) h -= 1 w -= 1 count_h[h] += 1 count_w[w] += 1 merge(h, w) root = -1 for i in range(200000): if count_h[i] + count_w[i]: if root == -1: root = find(i) elif find(i) != root: print(0) exit() ans = 0 diff = [] for i in range(200000): if abs(count_h[i] - count_w[i]) > 1: print(0) exit() elif count_h[i] != count_w[i]: diff.append(i) elif count_h[i]: ans += 1 if len(diff) > 2: print(0) elif diff: print(1) else: print(ans)