結果

問題 No.2574 Defect-free Rectangles
ユーザー AngrySadEightAngrySadEight
提出日時 2023-12-01 08:36:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 973 ms / 2,000 ms
コード長 1,164 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 221,792 KB
最終ジャッジ日時 2023-12-01 08:36:49
合計ジャッジ時間 7,941 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
57,660 KB
testcase_01 AC 55 ms
59,708 KB
testcase_02 AC 59 ms
65,260 KB
testcase_03 AC 106 ms
76,660 KB
testcase_04 AC 105 ms
77,300 KB
testcase_05 AC 106 ms
76,660 KB
testcase_06 AC 242 ms
94,824 KB
testcase_07 AC 183 ms
92,404 KB
testcase_08 AC 180 ms
92,544 KB
testcase_09 AC 961 ms
221,408 KB
testcase_10 AC 781 ms
217,984 KB
testcase_11 AC 973 ms
221,532 KB
testcase_12 AC 958 ms
221,792 KB
testcase_13 AC 685 ms
217,480 KB
testcase_14 AC 394 ms
122,740 KB
testcase_15 AC 265 ms
99,272 KB
testcase_16 AC 163 ms
84,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

H, W, N = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)
c = [[0 for _ in range(W)] for _ in range(H)]
for i in range(N):
    c[A[i]][B[i]] = 1
length = [[0 for _ in range(W)] for _ in range(H)]
for j in range(W):
    if c[H - 1][j] == 0:
        length[H - 1][j] = 1
    else:
        length[H - 1][j] = 0
for i in reversed(range(H - 1)):
    for j in range(W):
        if c[i][j] == 0:
            length[i][j] = length[i + 1][j] + 1
        else:
            length[i][j] = 0

# print(length)
ans = 0
dq = deque()

dq.append([-1, -1])
now = 0

for i in range(H):
    for j in range(W):
        idx = j
        while True:
            if len(dq) == 0:
                break
            height, width = dq.pop()
            if height < length[i][j]:
                dq.append([height, width])
                break
            now -= height * width
            idx -= width
        now += length[i][j] * (j - idx + 1)
        ans += now
        dq.append([length[i][j], j - idx + 1])
    while len(dq):
        dq.pop()
    now = 0
print(ans)
0