結果

問題 No.2696 Sign Creation
ユーザー GOTKAKOGOTKAKO
提出日時 2024-03-22 22:31:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 2,500 ms
コード長 2,216 bytes
コンパイル時間 2,272 ms
コンパイル使用メモリ 224,944 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-05-17 18:14:12
合計ジャッジ時間 4,099 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 164 ms
7,424 KB
testcase_14 AC 62 ms
6,944 KB
testcase_15 AC 61 ms
6,940 KB
testcase_16 AC 147 ms
6,940 KB
testcase_17 AC 4 ms
6,940 KB
testcase_18 AC 11 ms
6,940 KB
testcase_19 AC 68 ms
6,944 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 39 ms
6,940 KB
testcase_22 AC 10 ms
6,944 KB
testcase_23 AC 45 ms
6,940 KB
testcase_24 AC 46 ms
6,940 KB
testcase_25 AC 90 ms
8,192 KB
testcase_26 AC 5 ms
6,944 KB
testcase_27 AC 9 ms
6,948 KB
testcase_28 AC 13 ms
6,944 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 3 ms
6,940 KB
testcase_31 AC 101 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 1 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int H,W,N,D; cin >> H >> W >> N >> D;
    vector<vector<bool>> star(H,vector<bool>(W)),already = star;
    while(N--){
        int x,y; cin >> x >> y;
        x--; y--;
        star.at(x).at(y) = true;
    }

    vector<vector<int>> dec(H,vector<int>(W)),inc = dec;
    int answer = 0;
    for(int i=0; i<H; i++) for(int k=0; k<W; k++){
        if(already.at(i).at(k) || !star.at(i).at(k)) continue;
        already.at(i).at(k) = true;
        stack<pair<int,int>> st;
        queue<pair<int,int>> Q;
        Q.push({i,k});
        while(Q.size()){
            auto[x,y] = Q.front(); Q.pop();
            st.push({x,y});
            for(int i=-5; i<=5; i++) for(int k=-5; k<=5; k++){
                if(abs(i)+abs(k) > D) continue;
                int nx = x+i,ny = y+k;
                if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
                if(already.at(nx).at(ny) || !star.at(nx).at(ny)) continue;
                already.at(nx).at(ny) = true; Q.push({nx,ny});
            }
        }
        bool ok = false;
        if(st.size() > 1) ok = true,answer++;
        set<pair<int,int>> added;
        while(st.size()){
            auto[x,y] = st.top(); st.pop();
            for(int i=-5; i<=5; i++) for(int k=-5; k<=5; k++){
                if(abs(i)+abs(k) > D) continue;
                int nx = x+i,ny = y+k;
                if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;     
                if(star.at(nx).at(ny)) continue;
                if(added.count({nx,ny})) continue;
                if(ok) dec.at(nx).at(ny)++;
                else inc.at(nx).at(ny)++;
                added.insert({nx,ny});               
            }
        }
    }

    int maxa = -1,mina = 1e9;
    for(int i=0; i<H; i++) for(int k=0; k<W; k++){
        if(star.at(i).at(k)) continue;
        if(dec.at(i).at(k)) mina = min(mina,answer-dec.at(i).at(k)+1),maxa = max(maxa,answer-dec.at(i).at(k)+1);
        else if(inc.at(i).at(k)) maxa = answer+1,mina = min(mina,answer+1);
        else maxa = max(maxa,answer),mina = min(mina,answer);
    }
    cout << mina << " " << maxa << endl;
}
0