結果
問題 | No.168 ものさし |
ユーザー |
|
提出日時 | 2016-08-30 21:21:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 149 ms / 2,000 ms |
コード長 | 1,658 bytes |
コンパイル時間 | 989 ms |
コンパイル使用メモリ | 85,312 KB |
実行使用メモリ | 11,740 KB |
最終ジャッジ日時 | 2024-12-24 07:14:25 |
合計ジャッジ時間 | 3,008 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <cmath>#include <cassert>#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)typedef long long ll;using namespace std;struct disjoint_sets {vector<int> xs;explicit disjoint_sets(size_t n) : xs(n, -1) {}bool is_root(int i) { return xs[i] < 0; }int find_root(int i) { return is_root(i) ? i : (xs[i] = find_root(xs[i])); }int set_size(int i) { return - xs[find_root(i)]; }int union_sets(int i, int j) {i = find_root(i); j = find_root(j);if (i != j) {if (set_size(i) < set_size(j)) swap(i,j);xs[i] += xs[j];xs[j] = i;}return i;}bool is_same(int i, int j) { return find_root(i) == find_root(j); }};struct edge_t { int i, j; ll dist; };bool operator < (edge_t const & a, edge_t const & b) { return a.dist < b.dist; } // weak orderingint main() {// inputint n; cin >> n;vector<ll> x(n), y(n); repeat (i,n) cin >> x[i] >> y[i];// computevector<edge_t> que;repeat (j,n) {repeat (i,j) {ll dist = ceill(hypotl(x[j] - x[i], y[j] - y[i]));que.push_back((edge_t) { i, j, dist });}}whole(sort, que);disjoint_sets t(n);ll ans = 0;for (edge_t e : que) {ans = e.dist;t.union_sets(e.i, e.j);if (t.is_same(0, n-1)) break;}assert (t.is_same(0, n-1));// outputif (ans % 10 != 0) ans += 10 - ans % 10;cout << ans << endl;return 0;}