結果
問題 | No.1605 Matrix Shape |
ユーザー | 炭酸水 |
提出日時 | 2022-05-19 23:14:09 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,551 ms / 2,000 ms |
コード長 | 1,244 bytes |
コンパイル時間 | 100 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 62,116 KB |
最終ジャッジ日時 | 2024-09-19 03:59:13 |
合計ジャッジ時間 | 21,045 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
10,880 KB |
testcase_01 | AC | 28 ms
10,880 KB |
testcase_02 | AC | 28 ms
10,880 KB |
testcase_03 | AC | 28 ms
10,880 KB |
testcase_04 | AC | 27 ms
10,752 KB |
testcase_05 | AC | 28 ms
10,880 KB |
testcase_06 | AC | 26 ms
11,008 KB |
testcase_07 | AC | 26 ms
10,880 KB |
testcase_08 | AC | 27 ms
10,880 KB |
testcase_09 | AC | 26 ms
10,752 KB |
testcase_10 | AC | 28 ms
11,008 KB |
testcase_11 | AC | 28 ms
10,880 KB |
testcase_12 | AC | 28 ms
10,880 KB |
testcase_13 | AC | 27 ms
11,008 KB |
testcase_14 | AC | 28 ms
10,880 KB |
testcase_15 | AC | 27 ms
10,752 KB |
testcase_16 | AC | 31 ms
10,880 KB |
testcase_17 | AC | 27 ms
10,752 KB |
testcase_18 | AC | 28 ms
10,880 KB |
testcase_19 | AC | 1,551 ms
61,876 KB |
testcase_20 | AC | 1,191 ms
35,780 KB |
testcase_21 | AC | 1,191 ms
36,272 KB |
testcase_22 | AC | 1,538 ms
60,596 KB |
testcase_23 | AC | 1,522 ms
62,116 KB |
testcase_24 | AC | 1,548 ms
61,552 KB |
testcase_25 | AC | 760 ms
11,008 KB |
testcase_26 | AC | 764 ms
11,008 KB |
testcase_27 | AC | 771 ms
11,008 KB |
testcase_28 | AC | 750 ms
10,880 KB |
testcase_29 | AC | 771 ms
11,008 KB |
testcase_30 | AC | 1,087 ms
34,728 KB |
testcase_31 | AC | 1,063 ms
34,804 KB |
testcase_32 | AC | 927 ms
22,620 KB |
testcase_33 | AC | 930 ms
22,672 KB |
testcase_34 | AC | 731 ms
10,880 KB |
testcase_35 | AC | 1,179 ms
48,528 KB |
testcase_36 | AC | 738 ms
36,408 KB |
ソースコード
n = int(input()) P_C = {} C_P = {} v = set() z = {} for _ in range(n): x, y = map(int, input().split()) if x in v: z[x] += 1 else: v.add(x) z[x] = 1 if y in v: z[y] -= 1 else: v.add(y) z[y] = -1 x_P = C_P.get(x, 0) y_P = C_P.get(y, 0) if x_P == 0 and y_P == 0: C_P[x] = x C_P[y] = x P_C[x] = [x, y] elif x_P == 0: C_P[x] = y_P P_C[y_P].append(x) elif y_P == 0: C_P[y] = x_P P_C[x_P].append(y) elif x_P != y_P: if len(P_C[x_P]) >= len(P_C[y_P]): P = P_C[y_P].copy() P_0 = x_P P_1 = y_P else: P = P_C[x_P].copy() P_0 = y_P P_1 = x_P for i in P: C_P[i] = P_0 P_C[P_0] += P del P_C[P_1] count_p1 = 0 count_0 = 0 count_m1 = 0 for i in v: if z[i] == 0: count_0 += 1 elif z[i] == 1: count_p1 += 1 elif z[i] == -1: count_m1 += 1 if len(P_C) ==1 and count_m1 == 1 and count_p1 == 1 and count_0 == len(v) - 2: print(1) elif len(P_C) ==1 and count_0 == len(v): print(len(v)) else: print(0)