結果

問題 No.94 圏外です。(EASY)
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-07 21:42:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,920 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 72,340 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 14:56:59
合計ジャッジ時間 1,804 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

class DisjointSet{
    public:
        vector<int> rank, p;//rank:木の高さ p:親の頂点番号
        DisjointSet(){}
        DisjointSet(int size){//頂点の数
            rank.resize(size, 0);
            p.resize(size, 0);
            rep(i, size) makeSet(i);
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
        //同じ木にあるか判定(今回使わない)
        bool same(int x, int y){
            return findSet(x) == findSet(y);
        }
        // 木どうしをくっつける
        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }
        //木の高さを考慮して木どうしをくっつける
        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x] == rank[y]) rank[y]++;
            }
        }
        //親を探す(ルートまで)
        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main(void){
	int n; cin >> n;
	if(n == 0){
		printf("1\n"); return 0;
	}
	vector<int> x(n);
	vector<int> y(n);
	rep(i, n) cin >> x[i] >> y[i];

	DisjointSet ds = DisjointSet(n);
	double now;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			now = (x[j] - x[i]) * (x[j] - x[i])
					  + (y[j] - y[i]) * (y[j] - y[i]);
			if(now <= 100){
				ds.unite(i, j);
			}
		}
	}

	double ans = 0;
	for (int i = 0; i < n; ++i){
		for (int j = i + 1; j < n; ++j){
			if(ds.same(i, j)){
				now = (x[j] - x[i]) * (x[j] - x[i])+ (y[j] - y[i]) * (y[j] - y[i]);
				ans = max(ans, now);
			}
		}
	}
	
	printf("%f\n", sqrt(ans) + 2.0);
	return 0;
}
0