結果

問題 No.168 ものさし
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-05-24 01:26:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,633 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 176,856 KB
実行使用メモリ 13,500 KB
最終ジャッジ日時 2024-04-17 20:51:42
合計ジャッジ時間 3,092 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 13 ms
6,944 KB
testcase_12 AC 45 ms
13,008 KB
testcase_13 AC 62 ms
13,360 KB
testcase_14 AC 62 ms
11,932 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 50 ms
13,500 KB
testcase_20 AC 50 ms
12,488 KB
testcase_21 AC 50 ms
12,204 KB
testcase_22 AC 53 ms
12,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.24 01:26:45
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

ll f(ll x1,ll x2, ll y1,ll y2) {
    ll res;
    for (res = ((ll)ceil(sqrt((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2)))) / 10 * 10; res * res < (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2); res+=10) {
    }
    return res;
}
// UnionFind
class UnionFind {
private:
    vector<int> par;
public:
    UnionFind(int n) {
        par.resize(n, -1);
    }
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    int n;cin >> n;
    vector<pair<int,int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    vector<tuple<ll,int,int>> v;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            v.push_back(make_tuple(f(a[i].first,a[j].first,a[i].second,a[j].second),i,j));
        }
    }
    sort(v.begin(), v.end());
    UnionFind uf(n);
    for (int i = 0; i < v.size(); i++) {
        uf.unite(get<1>(v[i]),get<2>(v[i]));
        if (uf.same(0,n-1)){
            cout << get<0>(v[i]) << endl;
            break;
        }
    }
    return 0;
}
0