結果

問題 No.168 ものさし
ユーザー mayoko_mayoko_
提出日時 2015-03-20 00:01:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 2,125 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 81,460 KB
実行使用メモリ 13,024 KB
最終ジャッジ日時 2023-08-25 20:43:00
合計ジャッジ時間 2,431 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
5,244 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 19 ms
5,448 KB
testcase_12 AC 60 ms
12,180 KB
testcase_13 AC 82 ms
11,356 KB
testcase_14 AC 83 ms
11,904 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,384 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 80 ms
12,460 KB
testcase_20 AC 84 ms
12,004 KB
testcase_21 AC 84 ms
13,024 KB
testcase_22 AC 84 ms
11,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;
typedef long long ll;

const int MAXN = 1024;
ll X[MAXN], Y[MAXN];
const ll INF = 1ll<<63;

ll square(ll x) {return x*x;}

ll lsqrt(ll n) {
    ll low = 0, high = 1ll<<31;
    while (high - low > 1) {
        ll med = (high + low) / 2;
        if (med * med <= n) low = med;
        else high = med;
    }
    return low;
}

// unionFind
const int UNION_MAX = 1024;
class unionFind {
    int par[UNION_MAX];
    int Rank[UNION_MAX];
public:
    void init(int nn) {
        for (int i = 0; i <= nn; i++) {
            par[i] = i;
            Rank[i] = 0;
        }
    }
    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);
        if (x == y) return;
        if (Rank[x] < Rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (Rank[x] == Rank[y]) Rank[x]++;
        }
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

unionFind uf;

int main(void) {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
    }
    priority_queue<pair<ll, pair<int, int> > > que;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            ll dist = lsqrt(square(X[i]-X[j]) + square(Y[i]-Y[j]));
            if (dist*dist < square(X[i]-X[j]) + square(Y[i]-Y[j])) {
                dist++;
            }
            if (dist % 10 == 0) que.push(make_pair(-dist/10*10, make_pair(i, j)));
            else que.push(make_pair(-(dist/10+1)*10, make_pair(i, j)));
        }
    }
    uf.init(N);
    ll ret = 10;
    while (1) {
        if (uf.same(0, N-1)) break;
        auto now = que.top(); que.pop();
        ret = -now.first;
        uf.unite(now.second.first, now.second.second);
    }
    cout << ret << endl;
    return 0;
}
0