結果

問題 No.168 ものさし
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-25 19:47:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,863 bytes
コンパイル時間 1,207 ms
コンパイル使用メモリ 118,780 KB
実行使用メモリ 15,852 KB
最終ジャッジ日時 2024-04-30 00:23:27
合計ジャッジ時間 3,125 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
6,492 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 2 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 24 ms
6,496 KB
testcase_12 AC 86 ms
15,852 KB
testcase_13 AC 143 ms
15,616 KB
testcase_14 AC 146 ms
15,704 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 132 ms
15,676 KB
testcase_20 AC 141 ms
15,732 KB
testcase_21 AC 145 ms
15,732 KB
testcase_22 AC 142 ms
15,724 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:84:9: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   84 |         if(solve(c, ans)) r=c;
      |         ^~
main.cpp:57:21: note: 'ans' was declared here
   57 |     long long N, c, ans, x, y, sq;
      |                     ^~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;
 
struct UnionFind {
    vector<long long> par;
    vector<long long> siz;
 
    UnionFind(long long N) : par(N), siz(N) {
        for(long long i = 0; i < N; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }
 
    long long root(long long x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(long long x, long long y) {
        long long rx = root(x);
        long long ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
        siz[ry] += siz[rx];
    }
 
    bool same(long long x, long long y) {
        long long rx = root(x);
        long long ry = root(y);
        return rx == ry;
    }
 
    long long size(long long x){
        return siz[root(x)];
    }
};

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;

bool solve(long long n, long long m){
    return n*n*100 >= m;
}
 
int main(){
 
    long long N, c, ans, x, y, sq;
    cin >> N;
    pq<tuple<long long, long long, long long>> que;
    vector<long long> X(N), Y(N);
    for (int i=0; i<N; i++) cin >> X[i] >> Y[i];
    UnionFind tree(N+1);
 
    for (int i=0; i<N; i++){
        for (int j=i+1; j<N; j++){
            long long dx = X[i]-X[j], dy = Y[i]-Y[j];
            c = dx*dx + dy*dy;
            que.push({c, i, j});
        }
    }
 
    while(!que.empty()){
        tie(c, x, y) = que.top();
        que.pop();
        if (!tree.same(0, N-1)){
            ans = c;
            tree.unite(x, y);
        }
    }

    long long l=0, r=2e8;
    while(r-l>1){
        c = (l+r)/2;
        if(solve(c, ans)) r=c;
        else l=c;
    }

    cout << r*10 << endl;
 
    return 0;
}
0