結果

問題 No.1605 Matrix Shape
ユーザー hir355hir355
提出日時 2021-07-16 21:34:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 561 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 117,652 KB
最終ジャッジ日時 2023-09-20 13:14:07
合計ジャッジ時間 9,416 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
80,608 KB
testcase_01 AC 84 ms
80,592 KB
testcase_02 AC 87 ms
80,636 KB
testcase_03 AC 88 ms
80,600 KB
testcase_04 WA -
testcase_05 AC 86 ms
80,596 KB
testcase_06 AC 89 ms
80,576 KB
testcase_07 AC 89 ms
80,568 KB
testcase_08 AC 88 ms
80,584 KB
testcase_09 AC 89 ms
80,808 KB
testcase_10 AC 88 ms
80,804 KB
testcase_11 AC 85 ms
79,864 KB
testcase_12 AC 89 ms
80,580 KB
testcase_13 AC 89 ms
80,608 KB
testcase_14 AC 90 ms
80,592 KB
testcase_15 AC 89 ms
80,688 KB
testcase_16 AC 85 ms
80,576 KB
testcase_17 AC 83 ms
79,808 KB
testcase_18 AC 82 ms
79,928 KB
testcase_19 AC 378 ms
117,300 KB
testcase_20 AC 361 ms
101,396 KB
testcase_21 AC 361 ms
101,604 KB
testcase_22 WA -
testcase_23 AC 383 ms
117,348 KB
testcase_24 AC 388 ms
117,652 KB
testcase_25 AC 227 ms
93,724 KB
testcase_26 AC 226 ms
93,744 KB
testcase_27 AC 228 ms
93,828 KB
testcase_28 WA -
testcase_29 AC 220 ms
93,932 KB
testcase_30 AC 363 ms
103,016 KB
testcase_31 AC 366 ms
103,404 KB
testcase_32 AC 321 ms
97,040 KB
testcase_33 WA -
testcase_34 AC 217 ms
96,328 KB
testcase_35 AC 322 ms
109,196 KB
testcase_36 AC 242 ms
101,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MAX = 2 * 10 ** 5
n = int(input())
g = [[] for _ in range(MAX + 1)]
inv = [0] * (MAX + 1)
out = [0] * (MAX + 1)
s = set()
for i in range(n):
    h, w = map(int, input().split())
    s.add(h)
    s.add(w)
    g[h].append(w)
    inv[w] += 1
    out[h] += 1
f1 = 0
f2 = 0
for i in range(MAX + 1):
    if inv[i] + 1 == out[i]:
        f1 += 1
    elif out[i] + 1 == inv[i]:
        f2 += 1
    elif inv[i] == out[i]:
        continue
    else:
        print(0)
        exit(0)
if f1 == f2 == 0:
    print(len(s))
elif f1 == f2 == 1:
    print(1)
else:
    print(0)
0