結果

問題 No.168 ものさし
ユーザー outlineoutline
提出日時 2021-02-01 20:13:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 2,404 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 141,692 KB
実行使用メモリ 11,460 KB
最終ジャッジ日時 2023-09-12 10:44:12
合計ジャッジ時間 3,910 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
5,176 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 54 ms
5,080 KB
testcase_12 AC 172 ms
8,912 KB
testcase_13 AC 243 ms
11,276 KB
testcase_14 AC 206 ms
11,396 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 154 ms
11,032 KB
testcase_20 AC 103 ms
11,292 KB
testcase_21 AC 158 ms
11,460 KB
testcase_22 AC 109 ms
11,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<ll> X(N), Y(N);
    for(int i = 0; i < N; ++i)  cin >> X[i] >> Y[i];
    
    vector<vector<ll>> d(N, vector<ll>(N));
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < i; ++j){
            ll dx = abs(X[i] - X[j]), dy = abs(Y[i] - Y[j]);
            d[i][j] = d[j][i] = dx * dx + dy * dy;
        }
    }

    auto bfs = [&](int s, ll bound){
        vector<ll> dist(N, INF);
        queue<int> que;
        dist[s] = 0;
        que.emplace(s);
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(int to = 0; to < N; ++to){
                if(to == from || d[from][to] > bound)   continue;
                if(chmin(dist[to], dist[from] + 1)){
                    que.emplace(to);
                }
            }
        }
        return dist;
    };

    ll lb = 0, ub = 3e+18;
    while(ub - lb > 1){
        ll mid = (lb + ub) / 2;
        auto dist1 = bfs(0, mid);
        auto distN = bfs(N - 1, mid);
        bool ok = false;
        for(int i = 0; i < N; ++i){
            if(dist1[i] != INF && distN[i] != INF)  ok = true;
        }
        if(ok)  ub = mid;
        else    lb = mid;
    }

    ll low = 0, high = 2e+9;
    while(high - low > 1){
        ll mid = (low + high) / 2;
        if(mid * mid >= ub) high = mid;
        else    low = mid;
    }

    cout << high / 10 * 10 + (high % 10 > 0) * 10 << endl;

    return 0;
}
0