結果

問題 No.168 ものさし
ユーザー CleyLCleyL
提出日時 2022-10-14 13:19:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,951 bytes
コンパイル時間 1,091 ms
コンパイル使用メモリ 94,892 KB
実行使用メモリ 12,940 KB
最終ジャッジ日時 2023-09-08 19:41:01
合計ジャッジ時間 2,247 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,184 KB
testcase_01 AC 2 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,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 7 ms
4,992 KB
testcase_12 AC 17 ms
11,408 KB
testcase_13 AC 21 ms
11,644 KB
testcase_14 AC 21 ms
11,732 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 22 ms
12,940 KB
testcase_20 AC 22 ms
12,272 KB
testcase_21 AC 23 ms
12,492 KB
testcase_22 AC 22 ms
11,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
const double EPS = 1e-8;
struct UnionFind {
  int n;
  vector<int> par;
  vector<int> size_;
  UnionFind(int n_) : n(n_), par((size_t)n_), size_((size_t)n_,1){
    for(int i = 0; n > i; i++)par[i] = i;
  }

  int root(int x){
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int a,int b){
    int ra = root(a);
    int rb = root(b);
    if(ra==rb)return;
    if(size(ra) > size(rb)) swap(ra,rb);
    par[ra] = rb;
    size_[rb] += size_[ra];
  }

  bool same(int a, int b){
    return root(a) == root(b);
  }

  int size(int a){
    return size_[root(a)];
  }
  void debug(){
    for(int i = 0; n > i; i++){
      cout << size_[root(i)] << " ";
    }
    cout << endl;

    return;
  }
};

struct d{
  int x,y;
  long long dist;
  bool operator<(const d &a)const{
    if(dist == a.dist){
      if(x == a.x)return y < a.y;
      return x < a.x;
    }
    return dist < a.dist;
  }
  bool operator==(const d &a)const{
    return dist==a.dist && x==a.x && y == a.y;
  }
  bool operator>(const d &a)const{
    return !((*this)<a ||(*this)==a);
  }
};

int main(){
  int n;cin>>n;
  vector<pair<long long,long long>> A(n);
  for(int i = 0; n > i; i++){
    cin>>A[i].first>>A[i].second;
  }
  priority_queue<d,vector<d>,greater<d>> B;
  for(int i = 0; n > i; i++){
    for(int j = i+1; n > j; j++){
      B.push({i,j,(A[i].first-A[j].first)*(A[i].first-A[j].first)+(A[i].second-A[j].second)*(A[i].second-A[j].second)});
    }
  }
  UnionFind C(n);
  while(C.size(0) != n){
    auto x = B.top();B.pop();
    C.unite(x.x,x.y);
    if(C.root(0) == C.root(n-1)){
      long long mn = 0;
      long long mx = 200000000;
      while(mx-mn > 1){
        long long ce = (mx+mn)/2;
        if(ce*ce*100 >= x.dist){
          mx = ce;
        }else{
          mn = ce;
        }
      }
      cout << mx*10 << endl;
      break;
    }
  }
}
0