結果

問題 No.2574 Defect-free Rectangles
ユーザー aplysiaSheepaplysiaSheep
提出日時 2023-11-30 19:12:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 2,792 ms
コンパイル使用メモリ 255,704 KB
実行使用メモリ 39,424 KB
最終ジャッジ日時 2023-11-30 19:12:45
合計ジャッジ時間 4,713 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 3 ms
6,548 KB
testcase_04 AC 5 ms
6,548 KB
testcase_05 AC 3 ms
6,548 KB
testcase_06 AC 47 ms
7,936 KB
testcase_07 AC 14 ms
7,552 KB
testcase_08 AC 13 ms
7,552 KB
testcase_09 AC 170 ms
39,296 KB
testcase_10 AC 91 ms
38,912 KB
testcase_11 AC 175 ms
39,296 KB
testcase_12 AC 177 ms
39,424 KB
testcase_13 AC 66 ms
38,912 KB
testcase_14 AC 67 ms
14,848 KB
testcase_15 AC 52 ms
9,088 KB
testcase_16 AC 31 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }

    vector<vector<int>> defects(h, vector<int>(w));
    for(int i = 0; i < n; ++i) defects[a[i]][b[i]] = 1;

    vector<int> dp(w);
    long long ans = 0;

    for(int i = 0; i < h; ++i) {
        vector<tuple<int, int, int>> stack;
        for(int j = 0; j < w; ++j) {
            if(defects[i][j]) {
                dp[j] = 0;
                stack.clear();
                continue;
            }
            dp[j]++;
            int k = dp[j];
            int t = 1;
            while(!stack.empty()) {
                auto [l, w, s] = stack.back();
                if(l < k) break;
                t += w;
                stack.pop_back();
            }

            if(stack.empty()) {
                stack.push_back({k, t, k * t});
                ans += k * t;
            } else {
                auto [l, w, s] = stack.back();
                stack.push_back({k, t, s + k * t});
                ans += s + k * t;
            }
        }
    }
    cout << ans << endl;
}
0