結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function 'bool DisjointSet::unite(int, int)':
main.cpp:29:5: warning: no return statement in function returning non-void [-Wreturn-type]
   29 |     }
      |     ^

ソースコード

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);
    }
    
    bool 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