結果

問題 No.2696 Sign Creation
ユーザー umezo
提出日時 2024-03-22 23:12:31
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 3,959 ms
コンパイル使用メモリ 273,248 KB
実行使用メモリ 191,780 KB
最終ジャッジ日時 2024-12-20 12:27:41
合計ジャッジ時間 23,431 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 20 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

class Dis{
  public:
  vector<ll> rank,p,siz;
  
  Dis(int s){
    rank.resize(s,0);
    p.resize(s,0);
    siz.resize(s,1);
    rep(i,s) makeSet(i);
  }
  
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
  
  bool same(int x,int y){
    return root(x)==root(y);
  }
  
  void unite(int x,int y){
    if(same(x,y)) return;
    link(root(x),root(y));
  }
  
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      siz[x]+=siz[y];
    }
    else{
      p[x]=y;
      siz[y]+=siz[x];
      if(rank[x]==rank[y]) rank[y]++;
    }
  }
  
  int root(int x){
    if(x != p[x]) p[x]=root(p[x]);
    return p[x];
  }
  
  int size(int x){
    return siz[root(x)];
  }
};

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int h,w,n,d;
  cin>>h>>w>>n>>d;
  vector<int> X(n),Y(n);
  rep(i,n) cin>>X[i]>>Y[i];
  map<pair<int,int>,set<int>> m;
  map<pair<int,int>,int> m1;
  rep(k,n){
    m1[{X[k],Y[k]}]=k;
  }
  Dis ds=Dis(n);
  rep(k,n){
    for(int i=-d;i<=d;i++){
      for(int j=-d-abs(i);j<=d+abs(i);j++){
        if(m1.count({X[k]+i,Y[k]+j})) ds.unite(k,m1[{X[k]+i,Y[k]+j}]);
        m[{X[k]+i,Y[k]+j}].insert(k);
      }
    }
  }
  int ma=0;
  rep(i,n){
    if(ds.root(i)==i && ds.size(i)>1) ma++;
  }
  int tmp=1;
  for(auto [a,b]:m){
    if(m1.count(a)) continue;
    set<int> s;
    for(auto x:b){
      s.insert(ds.root(x));
    }
    tmp=max(tmp,(int)s.size());
  }
  if(ma>0) cout<<ma-tmp+1<<" "<<ma<<endl;
  else cout<<0<<" "<<tmp-1<<endl;
  
  return 0;
}
0