結果

問題 No.168 ものさし
ユーザー machymachy
提出日時 2015-07-16 22:43:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 77,700 KB
実行使用メモリ 20,108 KB
最終ジャッジ日時 2023-08-25 20:58:15
合計ジャッジ時間 1,698 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
8,068 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 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,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 11 ms
8,208 KB
testcase_12 AC 12 ms
7,176 KB
testcase_13 AC 28 ms
20,108 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 13 ms
7,388 KB
testcase_20 AC 10 ms
7,380 KB
testcase_21 AC 30 ms
20,028 KB
testcase_22 AC 13 ms
7,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;
typedef long long LL;

LL distance2(vector<pair<int,int> >& p, int p1, int p2){
    LL dx = p[p1].first - p[p2].first;
    LL dy = p[p1].second - p[p2].second;
    return dx*dx + dy*dy;
}

int main(){
    int N;
    cin >> N;
    vector<pair<int,int> > p(N);
    for(int i = 0; i < N; i++){
        cin >> p[i].first >> p[i].second;
    }
    priority_queue<pair<LL,int>, vector<pair<LL,int> >, greater<pair<LL,int> > > q;
    q.push(pair<LL,int>(0, 0));
    LL max_dist = 0;
    vector<int> memo(N);
    while(!q.empty()){
        LL w = q.top().first;
        int pos = q.top().second;
        q.pop();
        max_dist = max(max_dist, w);
        if(pos == N-1) break;
        if(memo[pos]) continue;
        memo[pos] = 1;
        for(int i = 0; i < N; i++){
            LL dist2 = distance2(p, pos, i);
            q.push(pair<LL,int>(dist2, i));
        }
    }
    LL ans = LL(sqrt(max_dist)) / 10 * 10;
    while(ans*ans < max_dist) ans += 10;
    cout << ans << endl;

    return 0;
}
0