結果

問題 No.2696 Sign Creation
ユーザー aradarad
提出日時 2024-03-22 22:33:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,500 ms
コード長 2,383 bytes
コンパイル時間 5,558 ms
コンパイル使用メモリ 321,724 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-27 17:58:34
合計ジャッジ時間 7,359 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 88 ms
6,676 KB
testcase_14 AC 39 ms
6,676 KB
testcase_15 AC 35 ms
6,676 KB
testcase_16 AC 76 ms
6,676 KB
testcase_17 AC 22 ms
6,676 KB
testcase_18 AC 16 ms
6,676 KB
testcase_19 AC 41 ms
6,676 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 33 ms
6,676 KB
testcase_22 AC 29 ms
6,676 KB
testcase_23 AC 36 ms
6,676 KB
testcase_24 AC 35 ms
6,676 KB
testcase_25 AC 48 ms
6,676 KB
testcase_26 AC 22 ms
6,676 KB
testcase_27 AC 25 ms
6,676 KB
testcase_28 AC 19 ms
6,676 KB
testcase_29 AC 23 ms
6,676 KB
testcase_30 AC 24 ms
6,676 KB
testcase_31 AC 89 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0