結果

問題 No.2574 Defect-free Rectangles
ユーザー aplysiaSheepaplysiaSheep
提出日時 2023-11-13 07:11:23
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,166 bytes
コンパイル時間 3,051 ms
コンパイル使用メモリ 255,704 KB
実行使用メモリ 39,424 KB
最終ジャッジ日時 2023-11-13 07:18:53
合計ジャッジ時間 5,160 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 4 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 47 ms
7,936 KB
testcase_07 AC 14 ms
7,552 KB
testcase_08 AC 14 ms
7,552 KB
testcase_09 AC 174 ms
39,296 KB
testcase_10 AC 95 ms
38,912 KB
testcase_11 AC 179 ms
39,296 KB
testcase_12 AC 182 ms
39,424 KB
testcase_13 AC 69 ms
38,912 KB
testcase_14 AC 69 ms
14,848 KB
testcase_15 AC 55 ms
9,088 KB
testcase_16 AC 32 ms
6,676 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>> x;
        for(int j = 0; j < w; ++j) {
            if(defects[i][j]) {
                dp[j] = 0;
                x.clear();
                continue;
            }
            dp[j]++;
            int k = dp[j];
            int t = 1;
            while(!x.empty()) {
                auto [l, w, s] = x.back();
                if(l < k) break;
                t += w;
                x.pop_back();
            }

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