結果

問題 No.168 ものさし
ユーザー ttakanottakano
提出日時 2017-12-09 10:16:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,555 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 144,856 KB
実行使用メモリ 11,368 KB
最終ジャッジ日時 2023-08-25 21:06:29
合計ジャッジ時間 2,814 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
7,368 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 7 ms
4,384 KB
testcase_11 AC 34 ms
7,480 KB
testcase_12 AC 107 ms
9,956 KB
testcase_13 AC 150 ms
11,368 KB
testcase_14 AC 150 ms
11,244 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 6 ms
4,740 KB
testcase_19 AC 65 ms
11,068 KB
testcase_20 AC 67 ms
11,228 KB
testcase_21 AC 69 ms
11,184 KB
testcase_22 AC 68 ms
11,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 10000000007; //10^9+7

int n;
ll x[1003];
ll y[1003];
ll d[1003][1003];

int par[10002]; //親を表す
int myrank[10002];  //木の深さを表す

void init(int n){   //初期化
  REP(i,n){
    par[i]=i;
    myrank[i]=0;
  }
}

int find(int x){    //親を見つける
  if(par[x]==x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}

void unit(int x, int y){    //x,yを併合
  x=find(x);
  y=find(y);
  if(x==y)return;

  if(myrank[x]<myrank[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(myrank[x]==myrank[y])myrank[x]++;
  }
}

bool same(int x, int y){    //x,yが同じグループか判定
  return find(x)==find(y);
}

bool solve(ll len){
  init(n);
  REP(i,n)REP(j,n){
    if(d[i][j]<=len*len){
      unit(i,j);
    }
  }
  return same(0,n-1);
}

int main(){
  cin>>n;
  REP(i,n)cin>>x[i]>>y[i];
  REP(i,n)REP(j,n){
    d[i][j]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
  }
  ll left=0, right=mod;
  while(right-left>1){
    ll mid=(left+right)/2;
    if(solve(mid)){
      right=mid;
    }else{
      left=mid+1;
    }
  }
  ll ans=left;
  REP(i,11){
    if(ans%10==0){
      if(solve(ans))break;
    }
    ans++;
  }
  print(ans);
  return 0;
}
0