結果

問題 No.94 圏外です。(EASY)
コンテスト
ユーザー yuppe19 😺
提出日時 2015-06-26 07:41:32
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,706 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,545 ms
コンパイル使用メモリ 175,712 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-03-08 16:02:50
合計ジャッジ時間 2,225 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |   int n; scanf("%d", &n);
      |          ~~~~~^~~~~~~~~~
main.cpp:47:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |     int x, y; scanf("%d%d", &x, &y);
      |               ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
using namespace std;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

class Point {
public:
  int x, y;
  Point(void) {}
  Point(int _x, int _y) { x = _x, y = _y; }
  int distdist(const Point& other) const {
    int xx = (x - other.x), yy = (y - other.y);
    return xx * xx + yy * yy;
  }
};

struct UnionFind {
private:
  vector<int> table;
public:
  UnionFind(int);
  int find(int);
  void unite(int, int);
};
UnionFind::UnionFind(int size) {
  table.assign(size, -1);
}
int UnionFind::find(int x) {
  if(table[x] < 0) { return x; }
  return table[x] = find(table[x]);
}
void UnionFind::unite(int x, int y) {
  int s1 = find(x), s2 = find(y);
  if(s1 == s2) { return; }
  if(s1 > s2) { swap(s1, s2); }
  table[s1] += table[s2];
  table[s2] = s1;
}

int main(void) {
  int n; scanf("%d", &n);
  vector<vector<int>> dist(n, vector<int>(n, 0));
  vector<Point> v(n);
  for(int i : range(n)) {
    int x, y; scanf("%d%d", &x, &y);
    v[i] = Point(x, y);
  }
  UnionFind nya(n);
  for(int i : range(n)) {
    for(int j : range(n)) {
      int dd = v[i].distdist(v[j]);
      dist[i][j] = dd;
      dist[j][i] = dd;
      if(i == j) { continue; }
      if(dd > 10 * 10) { continue; }
      nya.unite(i, j);
    }
  }
  int res = 0;
  for(int i : range(n)) {
    for(int j : range(n)) {
      if(i == j) { continue; }
      if(nya.find(i) != nya.find(j)) { continue; }
      res = max(res, dist[i][j]);
    }
  }
  printf("%lf\n", sqrt(res) + 1 + (n>0));
  return 0;
}
0