結果

問題 No.2696 Sign Creation
ユーザー 👑 NachiaNachia
提出日時 2024-03-22 22:32:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,152 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 117,044 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-03-22 22:32:47
合計ジャッジ時間 3,164 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 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 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 20 ms
6,676 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 19 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,676 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 4 ms
6,676 KB
testcase_27 AC 4 ms
6,676 KB
testcase_28 AC 4 ms
6,676 KB
testcase_29 AC 4 ms
6,676 KB
testcase_30 WA -
testcase_31 AC 46 ms
6,912 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
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <array>
#include <cmath>
#include <atcoder/modint>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(i64 i=0; i<(i64)(n); i++)
#define repr(i,n) for(i64 i=(i64)(n)-1; i>=0; i--)
const i64 INF = 1001001001001001001;
const char* yn(bool x){ return x ? "Yes" : "No"; }
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
template<typename A> using nega_queue = std::priority_queue<A,std::vector<A>,std::greater<A>>;
using Modint = atcoder::static_modint<998244353>;
//#include "nachia/vec.hpp"
#include <atcoder/dsu>
using namespace std;

void testcase(){
    i64 H, W, N; cin >> H >> W >> N;
    i64 D; cin >> D;
    vector<pair<i64,i64>> P(N);
    for(auto& [x,y] : P){ cin >> x >> y; x--; y--; }
    sort(P.begin(), P.end());

    auto dist = [&](i64 a, i64 b) -> i64 {
        return abs(P[a].first - P[b].first) + abs(P[a].second - P[b].second);
    };

    vector<i64> iso(N);
    atcoder::dsu dsu(N);

    i64 a = 0;
    {
        vector<i64> lasti(W+D+5, -1);
        rep(i,N){
            auto [x,y] = P[i];
            for(i64 yy=max<i64>(y-D,0); yy<y+D; yy++){
                if(lasti[yy] >= 0 && dist(lasti[yy], i) <= D) dsu.merge(lasti[yy], i);
            }
            lasti[y] = i;
        }
        rep(i,N) if(dsu.leader(i) == i && dsu.size(i) != 1) a++;

        rep(i,N) if(dsu.size(i) == 1) iso[i] = 1;
    }

    i64 lb = a, ub = a;

    bool down_lb = false;
    {
        vector<i64> lasti(W+D*2+1, -1);
        rep(i,N) if(!iso[i]){
            auto [x,y] = P[i];
            for(i64 yy=max<i64>(y-D*2,0); yy<y+D*2; yy++){
                if(lasti[yy] >= 0 && dist(lasti[yy], i) <= D*2 && !dsu.same(lasti[yy], i)){
                    down_lb = true;
                }
            }
            lasti[y] = i;
        }
    }


    bool up_ub = false;
    
    vector<vector<int>> sp(H, vector<int>(W, -1));
    rep(i,N) if(!iso[i]) sp[P[i].first][P[i].second] = D;
    rep(y,H) rep(x,W-1) chmax(sp[y][x+1], sp[y][x] - 1);
    rep(y,H) rep(x,W-1) chmax(sp[y][x], sp[y][x+1] - 1);
    rep(y,H-1) repr(x,W) chmax(sp[y+1][x], sp[y][x] - 1);
    repr(y,H-1) rep(x,W) chmax(sp[y][x], sp[y+1][x] - 1);
    vector<vector<int>> spiso(H, vector<int>(W, -1));
    rep(i,N) if(iso[i]) spiso[P[i].first][P[i].second] = D;
    rep(y,H) rep(x,W-1) chmax(spiso[y][x+1], spiso[y][x] - 1);
    rep(y,H) rep(x,W-1) chmax(spiso[y][x], spiso[y][x+1] - 1);
    rep(y,H-1) repr(x,W) chmax(spiso[y+1][x], spiso[y][x] - 1);
    repr(y,H-1) rep(x,W) chmax(spiso[y][x], spiso[y+1][x] - 1);
    rep(y,H) rep(x,W) if(spiso[y][x] >= 0 && spiso[y][x] != D && sp[y][x] < 0) up_ub = true;

    if(down_lb) lb--;
    if(up_ub) ub++;

    cout << lb << " " << ub << "\n";
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    #ifdef NACHIA
    int T; cin >> T; for(int t=0; t<T; T!=++t?(cout<<'\n'),0:0)
    #endif
    testcase();
    return 0;
}
0