結果

問題 No.94 圏外です。(EASY)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-06-26 07:41:32
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,706 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 51,648 KB
最終ジャッジ日時 2024-04-27 02:08:19
合計ジャッジ時間 763 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:21:3: error: ‘vector’ does not name a type
   21 |   vector<int> table;
      |   ^~~~~~
main.cpp: In constructor ‘UnionFind::UnionFind(int)’:
main.cpp:28:3: error: ‘table’ was not declared in this scope; did you mean ‘mutable’?
   28 |   table.assign(size, -1);
      |   ^~~~~
      |   mutable
main.cpp: In member function ‘int UnionFind::find(int)’:
main.cpp:31:6: error: ‘table’ was not declared in this scope; did you mean ‘mutable’?
   31 |   if(table[x] < 0) { return x; }
      |      ^~~~~
      |      mutable
main.cpp:32:10: error: ‘table’ was not declared in this scope; did you mean ‘mutable’?
   32 |   return table[x] = find(table[x]);
      |          ^~~~~
      |          mutable
main.cpp: In member function ‘void UnionFind::unite(int, int)’:
main.cpp:38:3: error: ‘table’ was not declared in this scope; did you mean ‘mutable’?
   38 |   table[s1] += table[s2];
      |   ^~~~~
      |   mutable
main.cpp: In function ‘int main()’:
main.cpp:44:3: error: ‘vector’ was not declared in this scope
   44 |   vector<vector<int>> dist(n, vector<int>(n, 0));
      |   ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:44:17: error: expected primary-expression before ‘int’
   44 |   vector<vector<int>> dist(n, vector<int>(n, 0));
      |                 ^~~
main.cpp:45:15: error: expected primary-expression before ‘>’ token
   45 |   vector<Point> v(n);
      |               ^
main.cpp:45:17: error: ‘v’ was not declared in this scope
   45 |   vector<Point> v(n);
      |                 ^
main.cpp:54:7: error: ‘dist’ was not declared in this scope
   54 |       dist[i][j] = dd;
      |       ^~~~
main.cpp:66:22: error: ‘dist’ was not declared in this scope
   66 |       res = max(res, dist[i][j]);
      |                

ソースコード

diff #

#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