結果

問題 No.2696 Sign Creation
ユーザー 👑 Nachia
提出日時 2024-03-22 22:37:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 3,152 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 116,636 KB
最終ジャッジ日時 2025-02-20 12:08:50
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28 WA * 10
権限があれば一括ダウンロードができます

ソースコード

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) repr(x,W-1) chmax(sp[y][x], sp[y][x+1] - 1);
rep(y,H-1) rep(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) repr(x,W-1) chmax(spiso[y][x], spiso[y][x+1] - 1);
rep(y,H-1) rep(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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0