結果
問題 | No.2696 Sign Creation |
ユーザー |
![]() |
提出日時 | 2024-03-22 22:41:55 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 110 ms / 2,500 ms |
コード長 | 1,813 bytes |
コンパイル時間 | 3,804 ms |
コンパイル使用メモリ | 266,596 KB |
実行使用メモリ | 9,856 KB |
最終ジャッジ日時 | 2024-12-20 12:13:37 |
合計ジャッジ時間 | 5,711 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#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; }