結果

問題 No.168 ものさし
ユーザー face4face4
提出日時 2018-10-16 21:17:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 85,496 KB
実行使用メモリ 11,748 KB
最終ジャッジ日時 2024-04-20 20:39:16
合計ジャッジ時間 1,997 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
5,464 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 8 ms
5,460 KB
testcase_12 AC 17 ms
11,612 KB
testcase_13 AC 22 ms
11,744 KB
testcase_14 AC 23 ms
11,748 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 23 ms
11,612 KB
testcase_20 AC 23 ms
11,612 KB
testcase_21 AC 22 ms
11,744 KB
testcase_22 AC 23 ms
11,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

class DisjointSet{
  public:
    vector<int> rank, p;

    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }else{
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }

    int findSet(int x){
        if(x != p[x]){
            // path compression
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

typedef long long ll;

int main(){
    int n;
    cin >> n;

    ll x[n], y[n];
    for(int i = 0; i < n; i++)  cin >> x[i] >> y[i];

    priority_queue<pair<ll, pair<int,int>>> pq;
    DisjointSet uf(n);

    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            pq.push({-((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i])), {i, j}});
        }
    }

    ll sq = 0;
    while(!uf.same(0, n-1)){
        auto p = pq.top();  pq.pop();
        sq = -p.first;
        uf.unite(p.second.first, p.second.second);
    }

    // 105を引くのはsqrtの誤差対策
    ll ans = (ll)(sqrt(max(0ll,sq-105)))/10*10;
    while(ans*ans < sq) ans += 10;

    cout << ans << endl;

    return 0;
}
0