結果

問題 No.2696 Sign Creation
ユーザー kokoseikokosei
提出日時 2024-03-22 22:41:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,500 ms
コード長 1,813 bytes
コンパイル時間 3,356 ms
コンパイル使用メモリ 267,884 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-05-17 18:15:30
合計ジャッジ時間 5,474 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 105 ms
9,088 KB
testcase_14 AC 41 ms
8,960 KB
testcase_15 AC 35 ms
7,936 KB
testcase_16 AC 83 ms
7,552 KB
testcase_17 AC 41 ms
9,216 KB
testcase_18 AC 29 ms
8,704 KB
testcase_19 AC 49 ms
9,088 KB
testcase_20 AC 6 ms
6,940 KB
testcase_21 AC 27 ms
7,936 KB
testcase_22 AC 49 ms
9,728 KB
testcase_23 AC 39 ms
9,088 KB
testcase_24 AC 37 ms
9,088 KB
testcase_25 AC 65 ms
9,216 KB
testcase_26 AC 44 ms
9,472 KB
testcase_27 AC 49 ms
9,984 KB
testcase_28 AC 41 ms
9,984 KB
testcase_29 AC 43 ms
9,728 KB
testcase_30 AC 44 ms
9,728 KB
testcase_31 AC 94 ms
7,252 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 3 ms
6,944 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using ll = long long;

int H, W, N, D;
int X[101010], Y[101010];
bool inside(int x, int y){
    return 0 <= x && x < H && 0 <= y && y < W;
}
int val(int x, int y){
    return x * W + y;
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> H >> W >> N >> D;
    atcoder::dsu uf(H * W);
    vector<vector<bool>> ex(H, vector<bool>(W));
    for(int i = 0;i < N;i++){
        int x, y; cin >> x >> y;
        x--, y--;
        ex[x][y] = true;
        for(int dx = -D;dx <= D;dx++){
            for(int dy = -(D - abs(dx));dy <= D - abs(dx);dy++){
                int nx = x + dx, ny = y + dy;
                if(!inside(nx, ny) || !ex[nx][ny])continue;
                uf.merge(val(x, y), val(nx, ny));
            }
        }
    }
    int mn = 1e9, mx = 0;
    auto g = uf.groups();
    int now = 0;
    for(auto v : g){
        now += v.size() >= 2;
    }
    for(int x = 0;x < H;x++){
        for(int y = 0;y < W;y++){
            if(ex[x][y])continue;
            vector<int> l;
            for(int dx = -D;dx <= D;dx++){
                for(int dy = -D;dy <= D;dy++){
                    if(abs(dx) + abs(dy) > D)continue;
                    int nx = x + dx, ny = y + dy;
                    if(!inside(nx, ny) || !ex[nx][ny])continue;
                    l.push_back(uf.leader(val(nx, ny)));
                }
            }
            int nxt = now + 1;
            sort(l.begin(), l.end());
            l.erase(unique(l.begin(), l.end()), l.end());
            for(int v : l){
                nxt -= uf.size(v) >= 2;
            }
            if(l.size() == 0)nxt = now;
            mn = min(mn, nxt);
            mx = max(mx, nxt);
        }
    }
    cout << mn << " " << mx << endl;
    return 0;
}
0