結果
問題 | No.94 圏外です。(EASY) |
ユーザー | masa |
提出日時 | 2015-06-30 13:38:32 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 16 ms / 5,000 ms |
コード長 | 1,416 bytes |
コンパイル時間 | 628 ms |
コンパイル使用メモリ | 74,692 KB |
実行使用メモリ | 11,548 KB |
最終ジャッジ日時 | 2023-09-08 14:30:02 |
合計ジャッジ時間 | 1,871 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 3 ms
4,380 KB |
testcase_07 | AC | 5 ms
5,604 KB |
testcase_08 | AC | 8 ms
7,664 KB |
testcase_09 | AC | 15 ms
11,316 KB |
testcase_10 | AC | 16 ms
11,388 KB |
testcase_11 | AC | 16 ms
11,548 KB |
testcase_12 | AC | 16 ms
11,452 KB |
testcase_13 | AC | 16 ms
11,312 KB |
testcase_14 | AC | 15 ms
11,548 KB |
testcase_15 | AC | 15 ms
11,436 KB |
testcase_16 | AC | 14 ms
11,468 KB |
testcase_17 | AC | 14 ms
11,352 KB |
testcase_18 | AC | 15 ms
11,316 KB |
testcase_19 | AC | 13 ms
11,452 KB |
testcase_20 | AC | 2 ms
4,380 KB |
testcase_21 | AC | 2 ms
4,380 KB |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <string> #include <cmath> using namespace std; class UnionFind { public: vector<int> parent; int trees; UnionFind(int n) { trees = n; parent.assign(n, 0); for (int i = 0; i < n; i++) { parent[i] = i; } } int find(int x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x != y) { parent[x] = y; trees--; } } int count() { return trees; } }; int main() { int n; cin >> n; if (n == 0) { cout << 1 << endl; return 0; } vector<int> x(n, 0), y(n, 0); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } vector< vector<double> > len(n, vector<double>(n, 0)); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { len[i][j] = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2)); len[j][i] = len[i][j]; } } UnionFind uf(n); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (len[i][j] <= 10.0) { uf.unite(i, j); } } } double max_len = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (uf.same(i, j)) { max_len= max(max_len, len[i][j]); } } } max_len += 2; printf("%.9lf\n", max_len); return 0; }