結果

問題 No.2354 Poor Sight in Winter
ユーザー t98slidert98slider
提出日時 2023-06-16 22:41:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,091 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 175,768 KB
実行使用メモリ 5,380 KB
最終ジャッジ日時 2023-09-06 21:06:31
合計ジャッジ時間 3,549 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 58 ms
5,240 KB
testcase_12 AC 56 ms
5,296 KB
testcase_13 AC 76 ms
5,380 KB
testcase_14 AC 68 ms
5,324 KB
testcase_15 AC 66 ms
5,244 KB
testcase_16 AC 65 ms
5,360 KB
testcase_17 AC 70 ms
5,300 KB
testcase_18 AC 30 ms
4,468 KB
testcase_19 AC 55 ms
4,660 KB
testcase_20 AC 34 ms
4,552 KB
testcase_21 WA -
testcase_22 AC 14 ms
4,384 KB
testcase_23 AC 14 ms
4,376 KB
testcase_24 AC 44 ms
4,632 KB
testcase_25 AC 11 ms
4,380 KB
testcase_26 AC 9 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, x, y, gx, gy, x2, y2, d;
    cin >> n >> k;
    vector<pair<int,int>> a(n + 2);
    cin >> x >> y;
    a[n] = {x, y};
    cin >> gx >> gy;
    a[n + 1] = {gx, gy};
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        a[i] = {x, y};
    }
    int ng = -1, ok = 300000, mid;
    while(ng + 1 < ok){
        mid = (ng + ok) / 2;
        vector<vector<pair<int,int>>> g(n + 2);
        int L = mid;
        for(int i = 0; i < n + 2; i++){
            tie(x, y) = a[i];
            for(int j = i + 1; j < n + 2; j++){
                tie(x2, y2) = a[j];
                d = abs(x - x2) + abs(y - y2) - (i < n || j < n? mid : 0);
                if(d <= 0){
                    g[i].emplace_back(j, 0);
                    g[j].emplace_back(i, 0);
                }else if(mid >= 1){
                    g[i].emplace_back(j, (d + mid - 1) / mid);
                    g[j].emplace_back(i, (d + mid - 1) / mid);
                }
            }
        }
        vector<int> dp(n + 2, 1 << 30);
        rpriority_queue<pair<int,int>> pq;
        pq.emplace(0, n);
        dp[n] = 0;
        while(!pq.empty()){
            int d, v;
            tie(d, v) = pq.top();
            pq.pop();
            if(d > dp[v]) continue;
            for(auto &&pa : g[v]){
                int w, u;
                tie(u, w) = pa;
                if(d + w >= dp[u]) continue;
                dp[u] = d + w;
                pq.emplace(d + w, u);
            }
        }
        (dp[n + 1] <= k ? ok : ng) = mid;
    }
    cout << ok << '\n';
}
0