結果
| 問題 |
No.2696 Sign Creation
|
| コンテスト | |
| ユーザー |
arad
|
| 提出日時 | 2024-03-22 22:33:56 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 2,500 ms |
| コード長 | 2,383 bytes |
| コンパイル時間 | 6,272 ms |
| コンパイル使用メモリ | 323,000 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-20 12:10:46 |
| 合計ジャッジ時間 | 8,207 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using P = pair<ll,ll>;
using VP = vector<P>;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define out(x) cout << x << endl
#define dout(x) cout << fixed << setprecision(10) << x << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)(x.size())
#define re0 return 0
#define pcnt __builtin_popcountll
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int inf = 1e9;
constexpr ll INF = 1e18;
//using mint = modint1000000007;
using mint = modint998244353;
int main(){
ll h,w,n,d;
cin >> h >> w >> n >> d;
VL x(n),y(n);
VVL board(h,VL(w,-1));
rep(i,n){
cin >> x[i] >> y[i];
x[i]--,y[i]--;
board[x[i]][y[i]] = i;
}
VL di,dj;
for(ll i = -d;i <= d;i++){
for(ll j = -d;j <= d;j++){
if(abs(i)+abs(j) <= d){
di.emplace_back(i);
dj.emplace_back(j);
}
}
}
dsu uf(h*w);
rep(i,h)rep(j,w) if(board[i][j] != -1){
rep(v,sz(di)){
ll ni = i+di[v];
ll nj = j+dj[v];
if(ni < 0 || nj < 0 || ni >= h || nj >= w) continue;
if(board[ni][nj] != -1){
uf.merge(i*w+j,ni*w+nj);
}
}
}
ll now = 0;
rep(i,h)rep(j,w)if(board[i][j]!=-1&&uf.leader(i*w+j)==i*w+j&&uf.size(i*w+j)>=2)now++;
ll ansmx = 0,ansmn = INF;
rep(i,h)rep(j,w) if(board[i][j] == -1){
unordered_set<ll> seen;
ll flag = 0;
rep(v,sz(di)){
ll ni = i+di[v];
ll nj = j+dj[v];
if(ni < 0 || nj < 0 || ni >= h || nj >= w) continue;
if(board[ni][nj] != -1 && !seen.count(uf.leader(ni*w+nj))){
if(uf.size(ni*w+nj)>=2) seen.insert(uf.leader(ni*w+nj));
flag = 1;
}
}
chmin(ansmn,now-sz(seen)+flag);
chmax(ansmx,now-sz(seen)+flag);
}
cout << ansmn << ' ' << ansmx << endl;
}
arad