結果

問題 No.2574 Defect-free Rectangles
ユーザー 👑 rin204rin204
提出日時 2023-12-10 18:08:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 787 ms / 2,000 ms
コード長 602 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 147,236 KB
最終ジャッジ日時 2023-12-10 18:08:33
合計ジャッジ時間 6,636 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,588 KB
testcase_01 AC 45 ms
55,588 KB
testcase_02 AC 50 ms
61,120 KB
testcase_03 AC 81 ms
76,040 KB
testcase_04 AC 80 ms
76,000 KB
testcase_05 AC 84 ms
76,296 KB
testcase_06 AC 197 ms
84,824 KB
testcase_07 AC 159 ms
84,824 KB
testcase_08 AC 156 ms
84,824 KB
testcase_09 AC 771 ms
146,852 KB
testcase_10 AC 752 ms
147,108 KB
testcase_11 AC 787 ms
147,236 KB
testcase_12 AC 757 ms
147,236 KB
testcase_13 AC 420 ms
137,636 KB
testcase_14 AC 374 ms
98,852 KB
testcase_15 AC 217 ms
87,104 KB
testcase_16 AC 136 ms
78,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w, n = map(int, input().split())
C = [[1] * w for _ in range(h)]
for _ in range(n):
    a, b = map(int, input().split())
    C[a - 1][b - 1] = 0

for j in range(w):
    for i in range(1, h):
        if C[i][j] != 0:
            C[i][j] = C[i - 1][j] + 1

ans = 0
for row in C:
    tot = 0
    st = []
    for c in row:
        if c == 0:
            st = []
            tot = 0
            continue
        a = 1
        while st and st[-1][0] >= c:
            tot -= st[-1][0] * st[-1][1]
            a += st.pop()[1]
        st.append((c, a))
        tot += c * a

        ans += tot

print(ans)
0