結果

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

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:3: error: ‘vector’ was not declared in this scope
   21 |   vector<Point> v(n);
      |   ^~~~~~
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:21:15: error: expected primary-expression before ‘>’ token
   21 |   vector<Point> v(n);
      |               ^
main.cpp:21:17: error: ‘v’ was not declared in this scope
   21 |   vector<Point> v(n);
      |                 ^
main.cpp:26:17: error: expected primary-expression before ‘int’
   26 |   vector<vector<int>> cost(n, vector<int>(n, 0)),
      |                 ^~~
main.cpp:34:7: error: ‘cost’ was not declared in this scope
   34 |       cost[i][j] = dd;
      |       ^~~~
main.cpp:37:7: error: ‘route’ was not declared in this scope
   37 |       route[i][j] = 1;
      |       ^~~~~
main.cpp:44:9: error: ‘route’ was not declared in this scope
   44 |         route[i][j] = min(route[i][j], route[i][k] + route[k][j]);
      |         ^~~~~
main.cpp:51:10: error: ‘route’ was not declared in this scope
   51 |       if(route[i][j] >= inf) { continue; }
      |          ^~~~~
main.cpp:52:22: error: ‘cost’ was not declared in this scope
   52 |       res = max(res, cost[i][j]);
      |                      ^~~~
main.cpp:55:20: error: ‘sqrt’ was not declared in this scope
   55 |   printf("%lf\n",  sqrt(res) + 1 + (n>0));
      |                    ^~~~
main.cpp:20:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |   int n; scanf("%d", &n);
      |          ~~~~~^~~~~~~~~~
main.cpp:23:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |     int x, y; scanf("%d%d", &x, &y);
      |     

ソースコード

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; }
  bool operator==(const Point& other) const { return x == other.x && y == other.y; }
  int distdist(const Point& other) const { return (x - other.x) * (x - other.x) + (y - other.y) * (y - other.y); }
};

const int inf = 987654321;

int main(void) {
  int n; scanf("%d", &n);
  vector<Point> v(n);
  for(int i : range(n)) {
    int x, y; scanf("%d%d", &x, &y);
    v[i] = Point(x, y);
  }
  vector<vector<int>> cost(n, vector<int>(n, 0)),
                      route(n, vector<int>(n, inf));
//  for(int i : range(n)) {
//    route[i][i] = 0;
//  }
  for(int i : range(n-1)) {
    for(int j : range(i+1, n)) {
      int dd = v[i].distdist(v[j]);
      cost[i][j] = dd;
      cost[j][i] = dd;
      if(dd > 10 * 10) { continue; }
      route[i][j] = 1;
      route[j][i] = 1;
    }
  }
  for(int k : range(n)) {
    for(int i : range(n)) {
      for(int j : range(n)) {
        route[i][j] = min(route[i][j], route[i][k] + route[k][j]);
      }
    }
  }
  int res = 0;
  for(int i : range(n)) {
    for(int j : range(i+1, n)) {
      if(route[i][j] >= inf) { continue; }
      res = max(res, cost[i][j]);
    }
  }
  printf("%lf\n",  sqrt(res) + 1 + (n>0));
  return 0;
}
0