結果
| 問題 |
No.168 ものさし
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-16 21:13:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,609 bytes |
| コンパイル時間 | 879 ms |
| コンパイル使用メモリ | 84,632 KB |
| 実行使用メモリ | 13,556 KB |
| 最終ジャッジ日時 | 2024-10-12 18:45:23 |
| 合計ジャッジ時間 | 5,379 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 4 |
| other | RE * 19 |
コンパイルメッセージ
main.cpp: In member function 'bool DisjointSet::unite(int, int)':
main.cpp:29:5: warning: no return statement in function returning non-void [-Wreturn-type]
29 | }
| ^
ソースコード
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
class DisjointSet{
public:
vector<int> rank, p;
DisjointSet(){}
DisjointSet(int size){
rank.resize(size, 0);
p.resize(size, 0);
for(int i = 0; i < size; i++) makeSet(i);
}
void makeSet(int x){
p[x] = x;
rank[x] = 0;
}
bool same(int x, int y){
return findSet(x) == findSet(y);
}
bool unite(int x, int y){
link(findSet(x), findSet(y));
}
void link(int x, int y){
if(rank[x] > rank[y]){
p[y] = x;
}else{
p[x] = y;
if(rank[x] == rank[y]){
rank[y]++;
}
}
}
int findSet(int x){
if(x != p[x]){
// path compression
p[x] = findSet(p[x]);
}
return p[x];
}
};
typedef long long ll;
int main(){
int n;
cin >> n;
ll x[n], y[n];
for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
priority_queue<pair<ll, pair<int,int>>> pq;
DisjointSet uf(n);
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
pq.push({-((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i])), {i, j}});
}
}
ll sq = 0;
while(!uf.same(0, n-1)){
auto p = pq.top(); pq.pop();
sq = -p.first;
uf.unite(p.second.first, p.second.second);
}
// 105を引くのはsqrtの誤差対策
ll ans = (ll)(sqrt(max(0ll,sq-105)))/10*10;
while(ans*ans < sq) ans += 10;
cout << ans << endl;
return 0;
}