結果
問題 | No.2574 Defect-free Rectangles |
ユーザー |
![]() |
提出日時 | 2023-11-13 07:11:23 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 166 ms / 2,000 ms |
コード長 | 1,166 bytes |
コンパイル時間 | 3,047 ms |
コンパイル使用メモリ | 254,484 KB |
実行使用メモリ | 39,296 KB |
最終ジャッジ日時 | 2024-09-26 03:13:18 |
合計ジャッジ時間 | 5,263 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#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;}