結果

問題 No.168 ものさし
ユーザー たこしたこし
提出日時 2015-06-08 17:00:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,981 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 97,996 KB
実行使用メモリ 37,784 KB
最終ジャッジ日時 2023-08-25 20:57:06
合計ジャッジ時間 2,147 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,576 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 4 ms
4,856 KB
testcase_11 AC 14 ms
11,356 KB
testcase_12 AC 42 ms
30,748 KB
testcase_13 AC 53 ms
36,680 KB
testcase_14 AC 55 ms
36,776 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 5 ms
5,312 KB
testcase_19 AC 55 ms
36,108 KB
testcase_20 AC 58 ms
37,664 KB
testcase_21 AC 54 ms
36,620 KB
testcase_22 AC 59 ms
37,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF_MIN 100000000
#define INF 1145141919
#define INF_MAX 2147483647
#define LL_MAX 9223372036854775807
#define EPS 1e-10
#define PI acos(-1)
#define LL long long

using namespace std;

#define MAX_N 1001

int N;

class cPoint{
public:
  long double X, Y;
  cPoint(){}

  long double calcDistance(cPoint& p1){
    return sqrt(pow(X-p1.X, 2) + pow(Y-p1.Y, 2));
  }

};

cPoint Point[MAX_N];
typedef pair<long double, int> P;
vector<P> Edge[MAX_N];

long double dp[MAX_N];

long double solve(int s, int g){

  for(int i = 0; i < N; i++){
    dp[i] = sqrt(pow(1e9,2) + pow(1e9, 2)) + 10.0;
  }

  dp[s] = 0.0;

  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0.0, s));

  while(que.size()){

    P p = que.top();
    que.pop();

    long double dis = p.first;
    int pos = p.second;

    if(dp[pos] < dis)
      continue;

    for(int i = 0; i < Edge[pos].size(); i++){
      
      int nextPos = Edge[pos][i].second;
      long double nextd = Edge[pos][i].first;

      long double d = max(nextd, dis);

      if(dp[nextPos] > d){
	dp[nextPos] = d;
	que.push(P(d, nextPos));
      }
      
    }

  }

  return dp[g];

}

int main(){

  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> Point[i].X >> Point[i].Y;
  }

  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      long double dis = Point[i].calcDistance(Point[j]);
      Edge[i].push_back(P(dis, j));
      Edge[j].push_back(P(dis, i));
    }
  }

  long double d = solve(0, N-1);

  printf("%d\n", (int)(d + 10 - 1e-10) / 10 * 10);

  return 0;

}
0