結果

問題 No.2574 Defect-free Rectangles
ユーザー 沙耶花沙耶花
提出日時 2023-12-06 02:18:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 4,984 ms
コンパイル使用メモリ 265,808 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2023-12-06 02:18:28
合計ジャッジ時間 7,305 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
6,676 KB
testcase_04 AC 5 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 57 ms
7,552 KB
testcase_07 AC 18 ms
7,552 KB
testcase_08 AC 18 ms
7,552 KB
testcase_09 AC 206 ms
38,912 KB
testcase_10 AC 120 ms
38,912 KB
testcase_11 AC 203 ms
38,912 KB
testcase_12 AC 224 ms
38,912 KB
testcase_13 AC 88 ms
38,912 KB
testcase_14 AC 87 ms
14,720 KB
testcase_15 AC 63 ms
8,704 KB
testcase_16 AC 35 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main(){
	int H,W,N;
	cin>>H>>W>>N;
	vector a(H,vector<int>(W));
	rep(i,N){
		int x,y;
		cin>>x>>y;
		x--,y--;
		a[x][y] = 1;
	}
	long long ans = 0;
	vector<int> c(W);
	rep(i,H){
		rep(j,W){
			if(a[i][j])c[j] = 0;
			else c[j]++;
		}
		
		stack<pair<long long,long long>> S;
		S.emplace(-1,-1);
		long long cur = 0;
		rep(j,W){
			while(S.top().second >= c[j]){
				auto p = S.top();
				S.pop();
				cur -= p.second * (p.first - S.top().first);
			}
			cur += c[j] * (j - S.top().first);
			S.emplace(j,c[j]);
			ans += cur;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}
0