結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2020-06-04 19:24:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,688 bytes |
コンパイル時間 | 1,904 ms |
コンパイル使用メモリ | 178,120 KB |
実行使用メモリ | 11,740 KB |
最終ジャッジ日時 | 2024-11-30 00:03:20 |
合計ジャッジ時間 | 3,295 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 WA * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; struct UnionFind { vector<int> data; UnionFind(int n) { data.assign(n, -1); } bool unite(int x, int y) { x = root(x), y = root(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int root(int k) { if (data[k] < 0) return (k); return (data[k] = root(data[k])); } bool same(int x, int y) { return root(x) == root(y); } int size(int k) { return (-data[root(k)]); } }; int main() { int N; ll X[1010], Y[1010]; cin >> N; for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; } auto len_sqrt = [&](int i, int j) { ll dx = abs(X[i] - X[j]), dy = abs(Y[i] - Y[j]); return dx * dx + dy * dy; }; vector<pair<ll, pair<int, int>>> len; for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { len.push_back({len_sqrt(i, j), {i, j}}); } } sort(len.begin(), len.end()); UnionFind uf(N); ll ans = 0; for (auto& e : len) { auto p = e.second; uf.unite(p.first, p.second); ans = e.first; if (uf.same(0, N - 1)) break; } auto check = [&](ll x) { return x * x > ans; }; ll ok = 2e9; ll ng = 0; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (check(mid)) { ok = mid; } else { ng = mid; } } ok = (ok + 9) / 10 * 10; cout << ok << endl; }