結果

問題 No.168 ものさし
ユーザー CleyLCleyL
提出日時 2022-10-14 13:04:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,928 bytes
コンパイル時間 3,533 ms
コンパイル使用メモリ 94,416 KB
実行使用メモリ 12,528 KB
最終ジャッジ日時 2023-09-08 19:40:14
合計ジャッジ時間 2,494 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
5,140 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 7 ms
5,036 KB
testcase_12 AC 19 ms
11,944 KB
testcase_13 AC 23 ms
12,240 KB
testcase_14 AC 22 ms
12,020 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 3 ms
4,384 KB
testcase_19 AC 22 ms
11,572 KB
testcase_20 AC 23 ms
12,528 KB
testcase_21 AC 24 ms
11,652 KB
testcase_22 AC 23 ms
11,792 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)){
      if((long long)floor(sqrt(x.dist)) * (long long)floor(sqrt(x.dist)) == x.dist){
        cout << (long long)floor(sqrt(x.dist)) << endl;  
      }else{
        cout << (int)((sqrt(x.dist)+10-EPS)/10)*10 << endl;
      }
      break;
    }
  }
}
0