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