結果

問題 No.94 圏外です。(EASY)
ユーザー codershifthcodershifth
提出日時 2015-08-04 08:40:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 2,331 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 157,504 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 14:32:20
合計ジャッジ時間 2,302 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class NoServiceEasy {
public:
    ll   square(int x) { return x*x; }
    ll   dist2(const pair<int,int> &a, const pair<int,int> &b) {
            return square(a.first-b.first)+square(a.second-b.second);
    }
    void solve(void) {
            int N;
            cin>>N;

            // 中継局がないときは 1km が最大
            if (N==0)
            {
                cout<<1<<endl;
                return;
            }

            vector<pair<int,int>> xy;
            REP(i,N)
            {
                int x,y;
                cin>>x>>y;
                xy.emplace_back(x,y);
            }

            // 10km 以内にある中継局をつなぐことで作ったグループにたいして
            // そのグループ内での最長距離をもとめればよい
            vector<vector<int>> tree(N);
            REP(i,N)
            FOR(j,i+1,N)
            {
                if (dist2(xy[i],xy[j]) <= 10*10)
                {
                    tree[i].push_back(j);
                    tree[j].push_back(i);
                }
            }

            vector<bool> vis(N,false);
            vector<ll>   d2(N,0);
            function<void(int,int)> dfs = [&](int x, int root) {
                if (vis[x])
                    return;
                vis[x] = true;
                d2[root] = max(d2[root], dist2(xy[x], xy[root]));
                for (auto y : tree[x])
                {
                    if (vis[y])
                        continue;
                    dfs(y, root);
                }
            };

            // 木ではなく森になっているかもしれないので根を変えて試す
            // O(N^2)
            REP(root,N)
            {
                fill(RANGE(vis),false);
                dfs(root,root);
            }
            ll maxD2 = *max_element(RANGE(d2));
            cout<<setprecision(20)<<sqrt(maxD2)+2<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new NoServiceEasy();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0