結果

問題 No.1605 Matrix Shape
ユーザー trineutrontrineutron
提出日時 2021-07-16 21:44:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 674 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 12,912 KB
最終ジャッジ日時 2023-09-20 13:28:33
合計ジャッジ時間 16,985 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
12,792 KB
testcase_01 AC 145 ms
12,732 KB
testcase_02 AC 150 ms
12,788 KB
testcase_03 AC 147 ms
12,788 KB
testcase_04 WA -
testcase_05 AC 145 ms
12,800 KB
testcase_06 AC 149 ms
12,784 KB
testcase_07 AC 149 ms
12,752 KB
testcase_08 AC 151 ms
12,828 KB
testcase_09 AC 147 ms
12,896 KB
testcase_10 AC 145 ms
12,800 KB
testcase_11 AC 24 ms
12,912 KB
testcase_12 AC 148 ms
12,840 KB
testcase_13 AC 152 ms
12,788 KB
testcase_14 AC 151 ms
12,768 KB
testcase_15 AC 151 ms
12,728 KB
testcase_16 AC 147 ms
12,716 KB
testcase_17 AC 24 ms
12,812 KB
testcase_18 AC 24 ms
12,720 KB
testcase_19 AC 745 ms
12,732 KB
testcase_20 AC 738 ms
12,728 KB
testcase_21 AC 746 ms
12,812 KB
testcase_22 WA -
testcase_23 AC 744 ms
12,724 KB
testcase_24 AC 747 ms
12,700 KB
testcase_25 AC 729 ms
12,728 KB
testcase_26 AC 725 ms
12,752 KB
testcase_27 AC 733 ms
12,740 KB
testcase_28 AC 612 ms
12,752 KB
testcase_29 AC 732 ms
12,720 KB
testcase_30 AC 739 ms
12,784 KB
testcase_31 AC 736 ms
12,796 KB
testcase_32 AC 725 ms
12,908 KB
testcase_33 WA -
testcase_34 AC 684 ms
12,728 KB
testcase_35 AC 615 ms
12,784 KB
testcase_36 AC 329 ms
12,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
count_h = [0] * 200000
count_w = [0] * 200000
loop = [0] * 200000
for i in range(n):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    if h == w:
        loop[h] += 1
    else:
        count_h[h] += 1
        count_w[w] += 1
ans = 0
diff = []
for i in range(200000):
    if abs(count_h[i] - count_w[i]) > 1:
        print(0)
        exit()
    elif count_h[i] == 0 and count_w[i] == 0 and loop[i] != 0 and loop[i] != n:
        print(0)
        exit()
    elif count_h[i] != count_w[i]:
        diff.append(i)
    elif count_h[i] or loop[i]:
        ans += 1
if len(diff) > 2:
    print(0)
    exit()
if diff:
    print(1)
else:
    print(ans)
0