結果
問題 | No.168 ものさし |
ユーザー |
|
提出日時 | 2017-03-20 23:32:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 1,745 bytes |
コンパイル時間 | 2,072 ms |
コンパイル使用メモリ | 181,276 KB |
実行使用メモリ | 11,640 KB |
最終ジャッジ日時 | 2024-12-24 07:17:41 |
合計ジャッジ時間 | 3,426 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef tuple<ll, int, int> T; struct Union_Find { //各要素が属する集合の代表(根)を管理する //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい vector<int> data; Union_Find(int size) : data(size, -1) {} bool Union(int x, int y) { x = Find(x); y = Find(y); bool is_union = (x != y); if (is_union) { if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; } return is_union; } int Find(int x) { if (data[x] < 0) { //要素xが根である return x; } else { data[x] = Find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される return data[x]; } } bool same(int x, int y) { return Find(x) == Find(y); } int size(int x) { return -data[Find(x)]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> x(n), y(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; vector<T> es; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { ll dx = x[i] - x[j], dy = y[i] - y[j]; es.emplace_back(dx * dx + dy * dy, i, j); } } sort(es.begin(), es.end()); Union_Find uf(n); ll dmax = 0; for (T t : es) { dmax = get<0>(t); uf.Union(get<1>(t), get<2>(t)); if (uf.same(0, n - 1)) break; } ll ng = 0, ok = 2e8; while (ok - ng > 1) { ll mid = (ok + ng) / 2; if (mid * mid * 100 >= dmax) ok = mid; else ng = mid; } cout << ok * 10 << endl; return 0; }