結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2021-06-02 11:19:13 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 117 ms / 2,000 ms |
コード長 | 2,349 bytes |
コンパイル時間 | 1,703 ms |
コンパイル使用メモリ | 141,676 KB |
実行使用メモリ | 18,820 KB |
最終ジャッジ日時 | 2024-11-14 14:32:23 |
合計ジャッジ時間 | 3,648 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <cassert>#include <cmath>#include <algorithm>#include <iostream>#include <iomanip>#include <limits.h>#include <map>#include <queue>#include <string.h>#include <vector>using namespace std;typedef long long ll;const int MAX_N = 200000;vector<int> parent;vector<int> _rank;vector<int> _size;class UnionFind {public:UnionFind(int n) {for (int i = 0; i < n; ++i) {parent.push_back(i);_rank.push_back(0);_size.push_back(1);}}int find(int x) {if (parent[x] == x) {return x;} else {return parent[x] = find(parent[x]);}}void unite(int x, int y) {x = find(x);y = find(y);if (x == y) return;if (_rank[x] < _rank[y]) {parent[x] = y;_size[y] += _size[x];} else {parent[y] = x;_size[x] += _size[y];if (_rank[x] == _rank[y]) ++_rank[x];}}bool same(int x, int y) {return find(x) == find(y);}int size(int x) {return _size[find(x)];}};struct Edge {ll u;ll v;ll dist;Edge(ll u = -1, ll v = -1, ll dist = -1) {this->u = u;this->v = v;this->dist = dist;}bool operator>(const Edge &n) const {return dist > n.dist;}};int main() {int N;cin >> N;priority_queue <Edge, vector<Edge>, greater<Edge>> pque;vector<Edge> edges;ll x, y;for (int i = 0; i < N; ++i) {cin >> x >> y;edges.push_back(Edge(x, y));}for (int i = 0; i < N; ++i) {Edge e1 = edges[i];for (int j = i + 1; j < N; ++j) {Edge e2 = edges[j];ll dy = e1.u - e2.u;ll dx = e1.v - e2.v;ll dist = dy * dy + dx * dx;pque.push(Edge(i, j, dist));}}UnionFind uf(MAX_N);ll max_dist = 0;while (not pque.empty()) {Edge edge = pque.top();pque.pop();if (uf.same(0, N - 1)) continue;if (uf.same(edge.u, edge.v)) continue;// fprintf(stderr, "[%d, %d, %lld]\n", edge.u, edge.v, edge.dist);uf.unite(edge.u, edge.v);max_dist = max(max_dist, edge.dist);}ll ng = 0;ll ok = 3037000499;while (abs(ok - ng) >= 2) {ll x = (ok + ng) / 2;if (x * x >= max_dist) {ok = x;} else {ng = x;}}if (ok % 10 == 0) {cout << ok << endl;} else {cout << 10 * ((ok /10) + 1) << endl;}return 0;}