結果

問題 No.94 圏外です。(EASY)
ユーザー tokkakatokkaka
提出日時 2016-07-30 16:40:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 2,312 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 109,056 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 14:56:51
合計ジャッジ時間 2,037 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <tuple>
#include <climits>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;

class UnionFind
{
    using data_type = size_t;
    const data_type none = -1;
    vector<data_type> data_;
    set<data_type> roots_;
    vector<data_type> size_;

    data_type root(data_type index)
    {
        if(data_[index] == none)
            return index;
        data_[index] = root(data_[index]);
        return data_[index];
    }
public:

    UnionFind(data_type size)
        : data_(size, none), size_(size, 1)
    {
    }

    void unite(data_type a, data_type b)
    {
        a = root(a);
        b = root(b);
        if(a == b) return;
        if(size_[a] < size_[b]) {
            data_[b] = a;
            size_[b] = size_[a] + size_[b];
            roots_.erase(a);
            roots_.insert(b);
        } else {
            data_[a] = b;
            size_[a] = size_[a] + size_[b];
            roots_.erase(b);
            roots_.insert(a);
        }
    }

    bool isUnion(data_type a, data_type b)
    {
        return root(a) == root(b);
    }

    const set<data_type>& roots()
    {
        return roots_;
    }
};

int main()
{
    constexpr int repeater_range = 10;
    constexpr int tranceiver_range = 1;
    int N;
    cin >> N;
    if(N == 0) {
        cout << 1 << endl;
        return 0;
    }
    vector<int> X(N), Y(N);
    UnionFind uf(N);
    for(int i=0; i<N; i++)
        cin >> X[i] >> Y[i];

    for(int i=0; i<N; i++) {
        for(int j=i+1; j<N; j++) {
            const int distance_squared = (X[i]-X[j])*(X[i]-X[j]) + (Y[i]-Y[j])*(Y[i]-Y[j]);
            if(distance_squared <= repeater_range*repeater_range)
                uf.unite(i, j);
        }
    }
    size_t max_length = 0;
    for(const auto &x : uf.roots()) {
        for(int i=0; i<N; i++) {
            if(!uf.isUnion(x, i)) continue;
            const int distance_squared = (X[x]-X[i])*(X[x]-X[i]) + (Y[x]-Y[i])*(Y[x]-Y[i]);
            if(distance_squared > max_length) max_length = distance_squared;
        }
    }
    cout << setprecision(11) << sqrt(max_length) + 2 << endl;
}
0