結果

問題 No.2354 Poor Sight in Winter
ユーザー ぷらぷら
提出日時 2023-06-16 21:55:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,327 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 206,376 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-06 19:33:13
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,388 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 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 24 ms
4,384 KB
testcase_12 AC 26 ms
4,384 KB
testcase_13 AC 39 ms
4,384 KB
testcase_14 AC 36 ms
4,384 KB
testcase_15 AC 32 ms
4,384 KB
testcase_16 AC 33 ms
4,384 KB
testcase_17 AC 32 ms
4,384 KB
testcase_18 AC 12 ms
4,380 KB
testcase_19 AC 24 ms
4,384 KB
testcase_20 AC 14 ms
4,380 KB
testcase_21 AC 3 ms
4,384 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 8 ms
4,380 KB
testcase_24 AC 20 ms
4,380 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int inf = 1001001001;

bool chmin(int &x,int y) {
    if(x > y) {
        x = y;
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,K;
    cin >> N >> K;
    int sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    vector<int>x(N+2),y(N+2);
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    x[N] = sx,y[N] = sy;
    x[N+1] = gx,y[N+1] = gy;
    int l = 0,r = 1001001;
    while(l+1 < r) {
        int mid = (l+r)/2;
        vector<int>dist(N+2,inf);
        dist[N] = 0;
        priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>que;
        que.push({0,N});
        while(!que.empty()) {
            pair<int,int>a = que.top();
            que.pop();
            if(dist[a.second] != a.first) continue;
            for(int i = 0; i < N+2; i++) {
                if(i == a.second) continue;
                int nxt = abs(x[a.second]-x[i])+abs(y[a.second]-y[i]);
                nxt = (nxt-1)/mid+a.first;
                if(chmin(dist[i],nxt)) {
                    que.push({nxt,i});
                }
            }
        }
        if(dist[N+1] <= K) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    cout << r << "\n";
}
0