結果

問題 No.2354 Poor Sight in Winter
ユーザー AngrySadEightAngrySadEight
提出日時 2023-04-04 03:10:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 2,150 bytes
コンパイル時間 1,140 ms
コンパイル使用メモリ 86,056 KB
実行使用メモリ 7,644 KB
最終ジャッジ日時 2023-10-26 02:51:47
合計ジャッジ時間 3,498 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 54 ms
7,292 KB
testcase_12 AC 56 ms
7,292 KB
testcase_13 AC 73 ms
7,644 KB
testcase_14 AC 70 ms
7,644 KB
testcase_15 AC 61 ms
7,616 KB
testcase_16 AC 63 ms
7,616 KB
testcase_17 AC 68 ms
7,620 KB
testcase_18 AC 24 ms
5,708 KB
testcase_19 AC 48 ms
6,784 KB
testcase_20 AC 29 ms
5,968 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 14 ms
4,564 KB
testcase_23 AC 16 ms
4,596 KB
testcase_24 AC 39 ms
6,520 KB
testcase_25 AC 10 ms
4,400 KB
testcase_26 AC 8 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
typedef long long ll;

void dijkstra(vector<vector<pair<ll, ll>>> &graph, ll v, vector<ll> &dist, ll P){
    priority_queue<pair<ll, ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pque;
    pque.push(pair<ll,ll>(0, v));
    dist[v] = 0;
    while(pque.size()){
        pair<ll,ll> p = pque.top();
        pque.pop();
        if (dist[p.second] != p.first){
            continue;
        }
        for (auto x: graph[p.second]){
            if (dist[x.first] > dist[p.second] + (x.second + P - 1) / P - 1){
                dist[x.first] = dist[p.second] + (x.second + P - 1) / P - 1;
                pque.push(pair<ll,ll>(dist[x.first], x.first));
            }
        }
    }
}

int main(){
    ll N, K;
    cin >> N >> K;
    ll sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    vector<ll> x(N);
    vector<ll> y(N);
    for (ll i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    vector<vector<pair<ll, ll>>> graph(N + 2, vector<pair<ll,ll>>(0));
    for (ll i = 0; i < N; i++){
        for (ll j = 0; j < N; j++){
            if (i != j){
                graph[i].push_back(pair<ll,ll>(j, abs(x[i] - x[j]) + abs(y[i] - y[j])));
            }
        }
    }
    for (ll i = 0; i < N; i++){
        graph[i].push_back(pair<ll,ll>(N, abs(x[i] - sx) + abs(y[i] - sy)));
        graph[N].push_back(pair<ll,ll>(i, abs(x[i] - sx) + abs(y[i] - sy)));
    }
    for (ll i = 0; i < N; i++){
        graph[i].push_back(pair<ll,ll>(N + 1, abs(x[i] - gx) + abs(y[i] - gy)));
        graph[N + 1].push_back(pair<ll,ll>(i, abs(x[i] - gx) + abs(y[i] - gy)));
    }
    graph[N].push_back(pair<ll,ll>(N + 1, abs(sx - gx) + abs(sy - gy)));
    graph[N + 1].push_back(pair<ll,ll>(N, abs(sx - gx) + abs(sy - gy)));
    ll INF = 10000000;

    ll ng = 0;
    ll ok = 200000;
    while (ok - ng > 1){
        ll center = (ng + ok) / 2;
        vector<ll> dist(N + 2, INF);
        dijkstra(graph, N, dist, center);
        if (dist[N + 1] <= K){
            ok = center;
        }
        else{
            ng = center;
        }
    }
    cout << ok << endl;
}
0