結果

問題 No.2574 Defect-free Rectangles
コンテスト
ユーザー 👑 rin204
提出日時 2023-12-10 18:08:26
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 451 ms / 2,000 ms
+ 726µs
コード長 602 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 225 ms
コンパイル使用メモリ 96,076 KB
実行使用メモリ 156,160 KB
最終ジャッジ日時 2026-09-05 03:55:08
合計ジャッジ時間 5,159 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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