結果

問題 No.2696 Sign Creation
ユーザー GOTKAKOGOTKAKO
提出日時 2024-03-22 22:11:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,509 bytes
コンパイル時間 2,316 ms
コンパイル使用メモリ 226,540 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-05-17 18:11:14
合計ジャッジ時間 4,021 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 3 ms
6,940 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,944 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 4 ms
6,944 KB
testcase_28 AC 5 ms
6,940 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 AC 3 ms
6,940 KB
testcase_31 AC 87 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 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 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 1 ms
6,940 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;
    stack<pair<int,int>> st;
    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;
        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=0; 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});
            }
        }
        if(st.size() >= 2){
            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;
                    dec.at(nx).at(ny)++;
                    added.insert({nx,ny});               
                }
            }
        }
        else{
            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;
                    inc.at(nx).at(ny)++;
                }
            }
        }
    }

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