結果

問題 No.94 圏外です。(EASY)
ユーザー finefine
提出日時 2017-02-28 18:49:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,677 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 172,208 KB
実行使用メモリ 7,060 KB
最終ジャッジ日時 2023-09-08 15:06:13
合計ジャッジ時間 2,694 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct Union_Find {
    //各要素が属する集合の代表(根)を管理する
    //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
    vector<int> data;
    
    Union_Find(int size) : data(size, -1) {}
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        bool is_union = (x != y);
        if (is_union) {
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return is_union;
    }
    int Find(int x) {
        if (data[x] < 0) { //要素xが根である
            return x;
        } else {
            data[x] = Find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
            return data[x];
        }
    }
    bool same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -data[Find(x)];
    }
};


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

	Union_Find uf(n);
	vector< vector<int> > d2(n, vector<int>(n, 0));
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int X = x[i] - x[j], Y = y[i] - y[j];
			d2[i][j] = X * X + Y * Y;
			d2[j][i] = d2[i][j];
			if (d2[i][j] <= 100) uf.Union(i, j);
		}
	}

	double ans = 1.0;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			if (!uf.same(i, j)) continue;
			ans = max(ans, sqrt(d2[i][j]) + 2.0);
		}
	}
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}
0