結果

問題 No.2574 Defect-free Rectangles
ユーザー 👑 potato167potato167
提出日時 2023-12-06 00:20:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 2,879 ms
コンパイル使用メモリ 212,944 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-06 00:20:47
合計ジャッジ時間 5,340 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
6,676 KB
testcase_06 AC 53 ms
6,676 KB
testcase_07 AC 18 ms
6,676 KB
testcase_08 AC 17 ms
6,676 KB
testcase_09 AC 212 ms
6,676 KB
testcase_10 AC 132 ms
6,676 KB
testcase_11 AC 213 ms
6,676 KB
testcase_12 AC 219 ms
6,676 KB
testcase_13 AC 87 ms
6,676 KB
testcase_14 AC 80 ms
6,676 KB
testcase_15 AC 65 ms
6,676 KB
testcase_16 AC 37 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)

int main() {
    ll H,W,N;
    cin>>H>>W>>N;
    vector p(H,vector<bool>(W));
    rep(i,0,N){
        int a,b;cin>>a>>b;
        a--,b--;
        p[a][b]=1;
    }
    ll ans=0;
    vector<ll> q(W+2);
    rep(i,0,H){
        rep(j,0,W){
            q[j+1]++;
            if(p[i][j]) q[j+1]=0;
        }
        stack<int> st;
        st.push(0);
        rep(j,1,W+2){
            while((int)st.size()!=1){
                int a=st.top();
                if(q[a]<q[j]){
                    break;
                }
                st.pop();
                ll wid=j-st.top()-1;
                ll hig=q[a]-max(q[st.top()],q[j]);
                ans+=hig*(wid*(wid+1))/2;
            }
            st.push(j);
        }
    }
    cout<<ans<<"\n";
}
0