結果

問題 No.168 ものさし
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-01-07 23:24:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 2,034 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 89,252 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 20:41:15
合計ジャッジ時間 3,606 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,380 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,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 17 ms
4,380 KB
testcase_12 AC 52 ms
4,384 KB
testcase_13 AC 72 ms
4,376 KB
testcase_14 AC 72 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 36 ms
4,380 KB
testcase_20 AC 38 ms
4,376 KB
testcase_21 AC 39 ms
4,376 KB
testcase_22 AC 40 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000009

vector<int> x;
vector<int> y;

vector<int> uf, usz;
int nc;

void init(int n){
  vector<int> uf_(n);
  vector<int> usz_(n, 1);
  uf = uf_;
  usz = usz_;
  nc = n;

  for(int i = 0; i < uf.size(); i++){
    uf[i] = i;
  }
}

int find(int a){
  return (uf[a] == a) ? a : uf[a] = find(uf[a]);
}

void union_(int a, int b){
  a = find(a);
  b = find(b);

  if(a != b){
    if(usz[a] >= usz[b]){
      swap(a, b);
    }
    uf[a] = b;
    usz[b] += usz[a];
    nc--;
  }
}

int check_uf(int a, int b){
  return (find(a) == find(b)) ? 1 : 0;
}

int get_size(int a){
  return usz[find(a)];
}

int check(int n){
  long long d = n;
  init(x.sz);
  rep(i,0,x.sz){
    rep(j,i+1,x.sz){
      long long x1 = x[i];
      long long y1 = y[i];
      long long x2 = x[j];
      long long y2 = y[j];
      if((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)<=d*d){
        union_(i,j);
      }
    }
  }
  if(check_uf(0,x.sz-1)==1){
    return 1;
  }
  return 0;
}

int main(){
  int n;
  cin>>n;
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    x.pb(a);
    y.pb(b);
  }
  int low = 0;
  int high = 200000000;

  while(low < high){
    int mid = (high + low) >> 1;

    if(check(mid*10) == 1){
      high = mid;
    }
    else{
      low = mid + 1;
    }
  }
  cout << low*10 << endl;
  return 0;
}
/*
ものさしの長さを2分探索する問題です。
線がつながっているかどうかの確認はUnion-Findでやっています。
*/
0