結果

問題 No.2179 Planet Traveler
ユーザー umezoumezo
提出日時 2023-01-19 05:05:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 3,000 ms
コード長 1,645 bytes
コンパイル時間 2,223 ms
コンパイル使用メモリ 210,712 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 23:23:24
合計ジャッジ時間 5,701 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 90 ms
4,376 KB
testcase_12 AC 101 ms
4,376 KB
testcase_13 AC 95 ms
4,376 KB
testcase_14 AC 83 ms
4,376 KB
testcase_15 AC 83 ms
4,380 KB
testcase_16 AC 82 ms
4,376 KB
testcase_17 AC 95 ms
4,376 KB
testcase_18 AC 95 ms
4,376 KB
testcase_19 AC 95 ms
4,376 KB
testcase_20 AC 15 ms
4,376 KB
testcase_21 AC 91 ms
4,376 KB
testcase_22 AC 57 ms
4,380 KB
testcase_23 AC 50 ms
4,380 KB
testcase_24 AC 75 ms
4,376 KB
testcase_25 AC 63 ms
4,376 KB
testcase_26 AC 82 ms
4,376 KB
testcase_27 AC 15 ms
4,380 KB
testcase_28 AC 39 ms
4,380 KB
testcase_29 AC 75 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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 findSet(x)==findSet(y);
  }
  
  void unite(int x,int y){
    if(same(x,y)) return;
    link(findSet(x),findSet(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 findSet(int x){
    if(x != p[x]) p[x]=findSet(p[x]);
    return p[x];
  }
  
  int size(int x){
    return siz[findSet(x)];
  }
};

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

  int n;
  cin>>n;
  vector<ll> X(n),Y(n),T(n);
  rep(i,n) cin>>X[i]>>Y[i]>>T[i];
  
  auto p=[&](ll x)->ll{
    return x*x;
  };
  
  auto f=[&](ll x)->bool{
    Dis ds=Dis(n);
    rep(i,n){
      for(int j=i+1;j<n;j++){
        if(T[i]==T[j]){
          if(p(X[i]-X[j])+p(Y[i]-Y[j])<=x) ds.unite(i,j);
        }
        else{
          if(p(X[i])+p(Y[i])+p(X[j])+p(Y[j])<=x) ds.unite(i,j);
          else if(p(p(X[i])+p(Y[i])+p(X[j])+p(Y[j])-x)<=4*(p(X[i])+p(Y[i]))*(p(X[j])+p(Y[j]))) ds.unite(i,j);
        }
      }
    }
    if(ds.same(0,n-1)) return true;
    return false;
  };
  
  ll ok=1e18,ng=-1;
  while(ok-ng>1){
    ll mid=(ok+ng)/2;
    if(f(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;

  return 0;
}
0