結果

問題 No.2696 Sign Creation
ユーザー umezoumezo
提出日時 2024-03-22 23:12:31
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 3,827 ms
コンパイル使用メモリ 274,440 KB
実行使用メモリ 175,380 KB
最終ジャッジ日時 2024-03-22 23:12:46
合計ジャッジ時間 8,371 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 172 ms
15,360 KB
testcase_09 WA -
testcase_10 AC 50 ms
7,808 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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