結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2018-10-28 04:06:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,581 bytes |
コンパイル時間 | 1,952 ms |
コンパイル使用メモリ | 206,352 KB |
最終ジャッジ日時 | 2025-01-06 14:58:01 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h>using namespace std;using i64 = int64_t;using vi = vector<i64>;using vvi = vector<vi>;struct edge {int s, t;i64 dist;};vi par;int find(int x) {if (x == par[x]) return x;return par[x] = find(par[x]);}void unite(int x, int y) {x = find(x);y = find(y);par[x] = y;}bool same(int x, int y) {return find(x) == find(y);}int main() {int n;cin >> n;vector<edge> edges;using ii = pair<i64, i64>;vector<ii> as;for (int i = 0; i < n; i++) {int x, y;cin >> x >> y;as.push_back(ii(x, y));}for (int i = 0; i < n; i++) {for (int j = i + 1; j < n; j++) {edges.push_back((edge){i, j, (as[i].first - as[j].first) * (as[i].first - as[j].first) + (as[i].second - as[j].second) * (as[i].second -as[j].second)});}}sort(edges.begin(), edges.end(), [](edge a, edge b) {return a.dist < b.dist;});par = vi(n);iota(par.begin(), par.end(), 0);i64 ans = 0;for (auto& e: edges) {if (same(0, n - 1)) break;if (same(e.s, e.t)) continue;i64 d = e.dist;i64 l = 0, r = 2e9;while (l < r - 1) {i64 m = (l + r) / 2;if (m * m <= d) {l = m;} else {r = m;}}if (l * l == d) {ans = max(ans, (l + 9) / 10);} else {ans = max(ans, (l + 10) / 10);}unite(e.s, e.t);}cout << ans * 10 << endl;}