結果
問題 | No.168 ものさし |
ユーザー | kei |
提出日時 | 2018-09-07 01:42:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 4,009 bytes |
コンパイル時間 | 1,614 ms |
コンパイル使用メモリ | 178,824 KB |
実行使用メモリ | 21,504 KB |
最終ジャッジ日時 | 2024-11-24 15:03:32 |
合計ジャッジ時間 | 2,729 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,196 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 4 ms
6,816 KB |
testcase_11 | AC | 14 ms
8,068 KB |
testcase_12 | AC | 38 ms
21,136 KB |
testcase_13 | AC | 49 ms
20,128 KB |
testcase_14 | AC | 49 ms
20,120 KB |
testcase_15 | AC | 2 ms
6,816 KB |
testcase_16 | AC | 2 ms
6,824 KB |
testcase_17 | AC | 2 ms
6,816 KB |
testcase_18 | AC | 5 ms
6,816 KB |
testcase_19 | AC | 47 ms
20,424 KB |
testcase_20 | AC | 50 ms
20,696 KB |
testcase_21 | AC | 51 ms
20,024 KB |
testcase_22 | AC | 50 ms
21,504 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; } template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; } template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; } /* <url:https://yukicoder.me/problems/no/168> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ struct UnionFind{ vector<int> parent, rank; UnionFind(int n) : parent(n, -1), rank(n, 0) { } int find(int x){ if(parent[x] == -1) return x; else return (parent[x] = find(parent[x])); } bool unite(int x, int y){ x = find(x); y = find(y); if(x == y) return false; if(rank[x] < rank[y]) parent[x] = y; else parent[y] = x; if(rank[x] == rank[y]) rank[x]++; return true; } bool same(int x, int y){ return find(x) == find(y); } }; typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-9, pi = acos(-1.0); namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } Point input_point() {ld x, y; cin >> x >> y; return Point(x, y);} // 点の入力 bool eq(ld a, ld b) {return (abs(a - b) < eps);} // 誤差つき等号判定 ld dot(Point a, Point b) {return real(conj(a) * b);} // 内積 ld cross(Point a, Point b) {return imag(conj(a) * b);} // 外積 struct edge{ int u,v; ld cost; edge(int u,int v,ld c):u(u),v(v),cost(c){} bool operator < (const edge& o) const{ return cost < o.cost; } bool operator > (const edge& o) const{ return cost > o.cost; } }; ll solve(){ ll res = 0; int N; cin >> N; vector<Point> ps(N); for(int i = 0; i < N;i++) ps[i] = input_point(); priority_queue<edge,vector<edge>,greater<edge>> pq; for(int i = 0; i < N;i++){ for(int j = i+1; j < N;j++){ pq.push(edge(i,j,abs(ps[i]-ps[j]))); } } UnionFind UF(N); ld maxL = 0; while(pq.size()){ auto e = pq.top(); pq.pop(); //cout << e.u << " " << e.v << " " << e.cost << endl; if(UF.same(e.u,e.v)) continue; UF.unite(e.u,e.v); if(UF.same(0,N-1)){ maxL = e.cost; break;} } // vector<int> group; // for(int i = 0; i < N;i++){ // if(UF.same(0,i)) group.push_back(i); // } // // vector<ld> maxLen(N,LINF); // queue<int> q; q.push(0); maxLen[0] = 0; // while(q.size()){ // ll n = q.front(); q.pop(); // for(auto next:group){ // if(n == next) continue; // ld len = abs(ps[n]-ps[next]); // if(maxLen[next] > max(maxLen[n],len)){ // maxLen[next] = max(maxLen[n],len); // q.push(next); // } // } // } // ld maxL = maxLen[N-1]; res = ceil(maxL/10)*10; return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); cout << solve() << endl; return 0; }