結果

問題 No.2696 Sign Creation
ユーザー hato336hato336
提出日時 2024-03-22 23:12:34
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,026 ms / 2,500 ms
コード長 8,032 bytes
コンパイル時間 6,072 ms
コンパイル使用メモリ 336,216 KB
実行使用メモリ 15,748 KB
最終ジャッジ日時 2024-05-17 18:19:06
合計ジャッジ時間 9,842 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 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 8 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 6 ms
6,940 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 400 ms
7,032 KB
testcase_14 AC 129 ms
7,024 KB
testcase_15 AC 118 ms
7,028 KB
testcase_16 AC 358 ms
7,028 KB
testcase_17 AC 89 ms
6,944 KB
testcase_18 AC 73 ms
6,940 KB
testcase_19 AC 184 ms
6,940 KB
testcase_20 AC 12 ms
6,940 KB
testcase_21 AC 98 ms
8,988 KB
testcase_22 AC 171 ms
6,940 KB
testcase_23 AC 117 ms
6,940 KB
testcase_24 AC 111 ms
6,940 KB
testcase_25 AC 209 ms
6,944 KB
testcase_26 AC 147 ms
6,940 KB
testcase_27 AC 138 ms
6,944 KB
testcase_28 AC 113 ms
6,944 KB
testcase_29 AC 133 ms
6,940 KB
testcase_30 AC 141 ms
6,940 KB
testcase_31 AC 1,026 ms
15,748 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,944 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 1 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__)
#define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__)
#define OVERLOAD_REP(_1, _2, _3, _4, name, ...) name
#define REP1(n) for(ll i=0;i<n;i++)
#define REP2(i, n) for (ll i=0;i<n;i++)
#define REP3(i, a, n) for (ll i=a;i<n;i++)
#define REP4(i, a, b, n) for(ll i=a;i<n;i+=b)
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP4, REP3, REP2, REP1)(__VA_ARGS__)
#define OVERLOAD_RREP(_1, _2, _3, _4, name, ...) name
#define RREP1(n) for(ll i=n-1;i>=0;i--)
#define RREP2(i, n) for(ll i=n-1;i>=0;i--)
#define RREP3(i, a, n) for(ll i=n-1;i>=a;i--)
#define RREP4(i, a, b, n) for(ll i=n-1;i>=a;i-=b)
#define rrep(...) OVERLOAD_RREP(__VA_ARGS__, RREP4, RREP3, RREP2, RREP1)(__VA_ARGS__)
#define foa(a,v)  (auto& a : (v))
#define uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define len(n) (long long)(n).size()
#define pb push_back
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using vvs = vector<vs>;
using vvvs = vector<vvs>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vc = vector<char>;
using vvc = vector<vc>;
using vvvc = vector<vvc>;
using pll = pair<ll,ll>;
using vpll = vector<pll>;
template<class... T>
constexpr auto min(T... a){
    return min(initializer_list<common_type_t<T...>>{a...});
}
template<class... T>
constexpr auto max(T... a){
    return max(initializer_list<common_type_t<T...>>{a...});
}
template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}
ll POW(ll a,ll b){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
        }
        a *= a;
        b /= 2;
    }
    return ans;
}
ll MODPOW(ll a,ll b,ll c){
    ll ans = 1;
    while (b){
        if (b & 1){
            ans *= a;
            ans %= c;
        }
        a *= a;
        a %= c;
        b /= 2;
    }
    return ans;
}
#define OVERLOAD_POW(_1, _2, _3, name, ...) name
#define pow(...) OVERLOAD_POW(__VA_ARGS__, MODPOW, POW)(__VA_ARGS__)
#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__; input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; input(__VA_ARGS__)
#define CHA(...) char __VA_ARGS__; input(__VA_ARGS__)
#define VLL(name,length) vll name(length);rep(i,length){cin >> name[i];}
#define VVLL(name,h,w) vvll name(h,vll(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLL(name,a,b,c) vvvll name(a,vvll(b,vll(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VI(name,length) vi name(length);rep(i,length){cin >> name[i];}
#define VVI(name,h,w) vvi name(h,vi(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVI(name,a,b,c) vvvi name(a,vvll(b,vi(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VLD(name,length) vld name(length);rep(i,length){cin >> name[i];}
#define VVLD(name,h,w) vvld name(h,vld(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVLD(name,a,b,c) vvvld name(a,vvld(b,vld(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VC(name,length) vc name(length);rep(i,length){cin >> name[i];}
#define VVC(name,h,w) vvc name(h,vc(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVC(name,a,b,c) vvvc name(a,vvc(b,vc(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define VS(name,length) vs name(length);rep(i,length){cin >> name[i];}
#define VVS(name,h,w) vvs name(h,vs(w));rep(i,h)rep(j,w){cin >> name[i][j];}
#define VVVS(name,a,b,c) vvvs name(a,vvs(b,vs(c)));rep(i,a)rep(j,b)rep(k,c){cin >> name[i][j][k];}
#define PLL(name) pll name;cin>>name.first>>name.second;
#define VPLL(name,length) vpll name(length);rep(i,length){cin>>name[i].first>>name[i].second;}

void print(){cout << "\n";}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';}
void print(vll x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void print(vvll x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void print(vi x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void print(vvi x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void print(vvvi x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void print(vld x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void print(vvld x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void print(vvvld x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void print(vc x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void print(vvc x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void print(vvvc x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void print(vs x){rep(i,len(x)){cout << x[i];if(i!=len(x)-1){cout << " ";}else{cout << '\n';}}}
void print(vvs x){rep(i,len(x))rep(j,len(x[i])){cout << x[i][j];if(j!=len(x[i])-1){cout << " ";}else{cout << '\n';}}}
void print(vvvs x){rep(i,len(x))rep(j,len(x[i]))rep(k,len(x[i][j])){cout << x[i][j][k];if(k!=len(x[i][j])-1){cout << " ";}else if(j!=len(x[i])-1){cout << " | ";}else{cout << '\n';}}}
void print(pll x){cout << x.first << x.second << '\n';}
void print(vpll x){rep(i,len(x)){cout << x[i].first << x[i].second << '\n';}}

int main(){
    LL(h,w,n,d);
    vpll dxy;
    rep(x,-5,6){
        rep(y,-5,6){
            if(1 <= abs(x) + abs(y) && abs(x)+abs(y) <= d){
                dxy.push_back(make_pair(x,y));
            }
        }
    }
    unordered_set<ll> s;
    map<ll,ll> c;
    vpll l;
    rep(i,n){
        LL(x,y);
        x--;
        y--;
        s.insert(x * 10000000 + y);
        l.push_back(make_pair(x,y));
        c[x * 10000000 + y] = i;
    }
    dsu uf(n);
    rep(i,n){
        auto x = l[i].first;
        auto y = l[i].second;
        rep(j,len(dxy)){
            auto dx = dxy[j].first;
            auto dy = dxy[j].second;
            if(s.count((x+dx)*10000000+y+dy) >= 1){
                uf.merge(i,c[(x+dx)*10000000+y+dy]);
            }
        }
    }
    ll mi = 1000000000000;
    ll ma = -1000000000000;
    ll res = 0;
    rep(i,n){
        if(uf.leader(i) == i && uf.size(i) >= 2){
            res++;
        }
    }
    rep(i,h){
        rep(j,w){
            if(s.count(i*10000000+j) >= 1){
                continue;
            }
            unordered_set<ll> se;
            ll now = res;
            ll cnt = 0;
            rep(k,len(dxy)){
                auto dx = dxy[k].first;
                auto dy = dxy[k].second;
                if(s.count((i+dx)*10000000+j+dy) >= 1 && se.count(uf.leader(c[(i+dx)*10000000+j+dy])) == 0){
                    se.insert(uf.leader(c[(i+dx)*10000000+j+dy]));
                    if(cnt == 0){
                        cnt++;
                        if(uf.size(c[(i+dx)*10000000+j+dy]) == 1){
                            now++;
                        }
                    }
                    else{
                        if(uf.size(c[(i+dx)*10000000+j+dy]) >= 2){
                            now--;
                        }
                    }
                }
            }
            mi = min(mi,now);
            ma = max(ma,now);
        }
    }
    print(mi,ma);
}
0