結果

問題 No.168 ものさし
ユーザー kimiyukikimiyuki
提出日時 2016-08-30 21:21:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,658 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 85,492 KB
実行使用メモリ 12,628 KB
最終ジャッジ日時 2023-08-25 21:02:01
合計ジャッジ時間 2,971 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
5,260 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 29 ms
5,332 KB
testcase_12 AC 97 ms
12,592 KB
testcase_13 AC 136 ms
12,124 KB
testcase_14 AC 137 ms
12,108 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 133 ms
12,628 KB
testcase_20 AC 139 ms
11,852 KB
testcase_21 AC 138 ms
11,512 KB
testcase_22 AC 139 ms
12,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 ordering
int main() {
    // input
    int n; cin >> n;
    vector<ll> x(n), y(n); repeat (i,n) cin >> x[i] >> y[i];
    // compute
    vector<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));
    // output
    if (ans % 10 != 0) ans += 10 - ans % 10;
    cout << ans << endl;
    return 0;
}
0