結果
| 問題 |
No.168 ものさし
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-14 13:04:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,928 bytes |
| コンパイル時間 | 1,089 ms |
| コンパイル使用メモリ | 100,964 KB |
| 最終ジャッジ日時 | 2025-02-08 03:18:11 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 WA * 1 |
ソースコード
#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;
}
}
}