結果

問題 No.2354 Poor Sight in Winter
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-16 23:13:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,356 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 117,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 22:08:28
合計ジャッジ時間 3,222 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 64 ms
4,384 KB
testcase_12 AC 64 ms
4,384 KB
testcase_13 AC 80 ms
4,380 KB
testcase_14 AC 76 ms
4,380 KB
testcase_15 AC 71 ms
4,380 KB
testcase_16 AC 73 ms
4,384 KB
testcase_17 AC 74 ms
4,384 KB
testcase_18 AC 26 ms
4,380 KB
testcase_19 AC 51 ms
4,384 KB
testcase_20 AC 31 ms
4,380 KB
testcase_21 AC 4 ms
4,384 KB
testcase_22 AC 16 ms
4,380 KB
testcase_23 AC 16 ms
4,384 KB
testcase_24 AC 42 ms
4,380 KB
testcase_25 AC 11 ms
4,380 KB
testcase_26 AC 8 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;
using ll = long long; 

ll N, K;
vector<ll> x, y;

bool solve(ll P){
 
    ll from, alt, d;
    pq<pair<ll, ll>> que;
    vector<ll> dist(N+2, 1e18);
    vector<bool> visit(N+2);
 
    dist[0] = 0;
    que.push({0, 0});
 
    while(!que.empty()){
        tie(d, from) = que.top();
        que.pop();
        if (visit[from]) continue;
        visit[from] = 1;
        for (int to=0; to<N+2; to++){
            alt = d + max(((abs(x[to]-x[from])+abs(y[to]-y[from]))+P-1)/P-1, 0LL);
            if (alt < dist[to]){
                dist[to] = alt;
                que.push({dist[to], to});
            }
        }
    }

    return dist[N+1] <= K;
}

int main(){

    ll a, b;
    cin >> N >> K;
    cin >> a >> b;
    x.resize(N+2); y.resize(N+2);
    x[0] = a; y[0] = b;
    cin >> a >> b;
    x[N+1] = a; y[N+1] = b;
    for (int i=1; i<=N; i++){
        cin >> a >> b;
        x[i] = a; y[i] = b;
    }
    ll l=0, r=1e6, c;
    while(r-l>1){
        c = (l+r)/2;
        if (solve(c)) r=c;
        else l=c;
    }

    cout << r << endl;
}
0