結果

問題 No.94 圏外です。(EASY)
ユーザー not_522not_522
提出日時 2015-08-17 14:39:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,024 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 149,092 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 14:35:32
合計ジャッジ時間 2,534 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

class UnionFind {
private:
  int n;
  vector<int> a;
public:
  UnionFind(int n) : n(n), a(n, -1) {}
  int find(int x) {return a[x] < 0 ? x : (a[x] = find(a[x]));}
  bool equal(int x, int y) {return find(x) == find(y);}
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] = x;
    --n;
  }
  int size() {return n;}
  int size(int x) {return -a[find(x)];}
};

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];
  UnionFind uf(n);
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2) <= 100) uf.unite(i, j);
    }
  }
  double res = (n ? 2 : 1);
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (uf.equal(i, j)) res = max(res, hypot(x[i] - x[j], y[i] - y[j]) + 2);
    }
  }
  cout << fixed << setprecision(15) << res << endl;
}
0