結果

問題 No.168 ものさし
ユーザー koyoprokoyopro
提出日時 2015-10-11 23:42:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 1,255 ms
コンパイル使用メモリ 152,276 KB
実行使用メモリ 12,188 KB
最終ジャッジ日時 2023-08-25 21:00:14
合計ジャッジ時間 2,676 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,444 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 8 ms
7,172 KB
testcase_12 AC 18 ms
11,644 KB
testcase_13 AC 19 ms
12,104 KB
testcase_14 AC 7 ms
12,148 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,608 KB
testcase_19 AC 21 ms
11,988 KB
testcase_20 AC 14 ms
12,184 KB
testcase_21 AC 52 ms
12,188 KB
testcase_22 AC 16 ms
12,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define int long long
#define REP(i, n) for(int i=0; i<(n); i++)
struct P { int x, y; P(){}; P(int _x, int _y): x(_x), y(_y){}; };
int distance2(P a, P b) {
    return (int)pow(a.x - b.x, 2) + (int)pow(a.y - b.y, 2);
}

int N,T;
int V[1111][1111];
vector<P> P(1111);
bool isok(int len) {
    int border = pow(len, 2);
    queue<int> que;
    que.push(0);
    vector<bool> checked(N, false);
    while(que.size()) {
        int i = que.front();
        que.pop();
        if (checked[i]) continue;
        checked[i] = true;
        REP(j,N) {
            if (checked[j]) continue;
            if (V[i][j] <= border) {
                if (j == N-1) return true;
                que.push(j);
            }
        }
    }
    return false;
}
signed main()
{
    cin >> N;
    REP(i,N) cin >> P[i].x >> P[i].y;
    REP(i,N) REP(j,i) {
        int d = distance2(P[i], P[j]);
        V[i][j] = V[j][i] = d;
    }
    int high = (int)1e9 * 2;
    int low = 0;
    while(high - low > 10) {
        int mid = (high + low) /2;
        if (isok(mid)) {
            high = mid;
        } else {
            low = mid;
        }
    }
    int len = (low / 10) * 10;
    REP(i,10) {
        if (isok(len)) {
            break;
        }
        len += 10;
    }
    cout << len << endl;
    return 0;
}
0