結果
問題 |
No.168 ものさし
|
ユーザー |
![]() |
提出日時 | 2015-08-19 02:32:46 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 141 ms / 2,000 ms |
コード長 | 1,990 bytes |
コンパイル時間 | 1,692 ms |
コンパイル使用メモリ | 174,448 KB |
実行使用メモリ | 19,800 KB |
最終ジャッジ日時 | 2024-12-24 07:11:04 |
合計ジャッジ時間 | 3,626 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; class UnionFind { private: int n; vector<int> a; public: UnionFind(int n) : n(n), a(n, -1) {} int find(int x) {return a[x] < 0 ? x : (a[x] = find(a[x]));} bool equal(int x, int y) {return find(x) == find(y);} void unite(int x, int y) { x = find(x), y = find(y); if (x == y) return; if (a[x] > a[y]) swap(x, y); a[x] += a[y]; a[y] = x; --n; } int size() {return n;} int size(int x) {return -a[find(x)];} }; template<typename T> inline T gcd(T a, T b) { return __gcd(a, b); } template<typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; } template<typename T> inline T floor(T a, T b) { return floor(a / b) * b <= a ? floor(a / b) : floor(a / b) - 1; } template<typename T> inline T ceil(T a, T b) { return floor(a + b - 1, b); } template<typename T> inline T round(T a, T b) { return floor(a + b / 2); } template<typename T> inline T mod(T a, T b) { return a - floor(a, b) * b; } template<typename T> inline T factorial(T n) { return n <= 1 ? 1 : factorial(n - 1) * n; } template<typename T> inline T square(T n) { return n * n; } template<typename T> inline T cube(T n) { return n * n * n; } template<typename T> inline T norm(T x1, T y1, T x2, T y2) { return square(x1 - x2) + square(y1 - y2); } inline long long sqrt(long long n) { return sqrt((long double)n); } int main() { int n; cin >> n; vector<tuple<long long, long long>> p(n); for (auto& i : p) cin >> get<0>(i) >> get<1>(i); vector<tuple<long long, int, int>> dis; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { dis.emplace_back(make_tuple(norm(get<0>(p[i]), get<1>(p[i]), get<0>(p[j]), get<1>(p[j])), i, j)); } } sort(dis.begin(), dis.end()); UnionFind uf(n); for (const auto& d : dis) { uf.unite(get<1>(d), get<2>(d)); if (uf.equal(0, n - 1)) { cout << ceil(sqrt(get<0>(d) - 1) + 1, 10ll) * 10 << endl; return 0; } } }