結果

問題 No.11 カードマッチ
ユーザー gorugo30gorugo30
提出日時 2021-02-25 21:51:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 54 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 80,148 KB
最終ジャッジ日時 2024-04-08 22:06:29
合計ジャッジ時間 1,703 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 49 ms
68,592 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 50 ms
75,340 KB
testcase_07 AC 49 ms
69,800 KB
testcase_08 AC 51 ms
72,556 KB
testcase_09 AC 54 ms
80,148 KB
testcase_10 AC 53 ms
74,556 KB
testcase_11 AC 50 ms
73,264 KB
testcase_12 AC 51 ms
73,824 KB
testcase_13 AC 50 ms
72,888 KB
testcase_14 AC 51 ms
67,896 KB
testcase_15 AC 53 ms
64,312 KB
testcase_16 AC 48 ms
65,012 KB
testcase_17 AC 48 ms
64,928 KB
testcase_18 AC 47 ms
64,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

W = int(input())
H = int(input())
N = int(input())
hand = [tuple(map(int, input().split())) for i in range(N)]
hset = set(hand)
cntmark = [H] * (W + 1)
cntmark[0] = 0
cntnum = [W] * (H + 1)
cntnum[0] = 0
for m, n in hand:
    cntmark[m] -= 1
    cntnum[n] -= 1
ans = 0
donem = set()
donen = set()
for m, n in hand:
    if m not in donem:
        ans += cntmark[m]
        donem.add(m)
    if n not in donen:
        ans += cntnum[n]
        donen.add(n)
for i in range(N):
    mi, ni = hand[i]
    for j in range(i + 1, N):
        mj, nj = hand[j]
        if (mi, nj) not in hset:
            ans -= 1
            hset.add((mi, nj))
        if (mj, ni) not in hset:
            ans -= 1
            hset.add((mj, ni))
print(ans)
0