結果
問題 | No.168 ものさし |
ユーザー |
|
提出日時 | 2015-06-30 01:22:42 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 1,566 bytes |
コンパイル時間 | 799 ms |
コンパイル使用メモリ | 78,616 KB |
実行使用メモリ | 11,616 KB |
最終ジャッジ日時 | 2024-12-24 07:09:38 |
合計ジャッジ時間 | 2,111 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <cmath> using namespace std; typedef pair<long long, long long> PLL; class UnionFind { private: vector<int> parent; int trees; public: UnionFind() { } UnionFind(int n) { trees = n; parent.assign(n, 0); for (int i = 0; i < n; i++) { parent[i] = i; } } int find(int x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x != y) { parent[x] = y; trees--; } } int count() { return trees; } }; int main() { int n, x, y; vector<PLL> points; cin >> n; points.assign(n, PLL()); for (int i = 0; i < n; i++) { cin >> x >> y; points[i] = make_pair(x, y); } vector<PLL> length2; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { long long x = points[i].first - points[j].first; long long y = points[i].second - points[j].second; length2.push_back(make_pair(x * x + y * y, i * 10000 + j)); } } sort(length2.begin(), length2.end()); UnionFind uf(n); long long ans2 = -1; for (int i = 0; i < length2.size(); i++) { int x = length2[i].second / 10000; int y = length2[i].second % 10000; uf.unite(x, y); if (uf.same(0, n - 1)) { ans2 = length2[i].first; break; } } long long ans = sqrt(ans2); while(ans * ans < ans2) { ans++; } ans = (ans + 9) / 10 * 10; cout << ans << endl; return 0; }