結果

問題 No.168 ものさし
ユーザー ushitora_anqouushitora_anqou
提出日時 2017-12-26 23:11:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,847 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 145,444 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 21:07:42
合計ジャッジ時間 2,717 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 21 ms
4,376 KB
testcase_12 AC 69 ms
4,384 KB
testcase_13 AC 98 ms
4,384 KB
testcase_14 AC 97 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 65 ms
4,380 KB
testcase_20 AC 67 ms
4,380 KB
testcase_21 AC 69 ms
4,376 KB
testcase_22 AC 70 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define mp make_pair
#define P pair
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))
#define modp(x, y) (((y) + (x) % (y)) % (y))
#define divd(x, y) (static_cast<double>(x) / static_cast<double>(y))
#define sq(x) (x) * (x)

template <ll SIZE>
class UnionFind {
public:
    using type = ll;  // must be integer type

private:
    std::array<ll, SIZE> parent_, rank_;

public:
    UnionFind()
    {
        for (ll i = 0; i < SIZE; i++) {
            parent_[i] = i;
            rank_[i] = 0;
        }
    }

    ll operator[](ll x)
    {
        if (parent_[x] == x)
            return x;
        else
            return parent_[x] = (*this)[parent_[x]];
    }

    void unite(ll x, ll y)
    {
        x = (*this)[x];
        y = (*this)[y];
        if (x == y) return;

        if (rank_[x] < rank_[y]) {
            parent_[x] = y;
        }
        else {
            parent_[y] = x;
            if (rank_[x] == rank_[y]) rank_[x]++;
        }
    }
};

ll N, X[2000], Y[2000];

bool C(ll l)
{
    UnionFind<2000> uf;
    rep(i, 0, N)
    {
        rep(j, 0, N)
        {
            if (sq(X[j] - X[i]) + sq(Y[j] - Y[i]) <= sq(l)) uf.unite(i, j);
        }
    }
    return (uf[0] == uf[N - 1]);
}

int main()
{
    //
    cin >> N;
    rep(i, 0, N) { cin >> X[i] >> Y[i]; }

    ll lb = 0, ub = 2E9;
    while (ub - lb > 1) {
        ll mid = (lb + ub) / 2;
        mid = mid / 10 * 10;
        if (mid == lb) break;

        if (C(mid))
            ub = mid;
        else
            lb = mid;
    }
    cout << ub << endl;
}
0