結果

問題 No.2354 Poor Sight in Winter
ユーザー shinchanshinchan
提出日時 2023-06-17 01:38:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 207,728 KB
実行使用メモリ 5,320 KB
最終ジャッジ日時 2023-09-07 00:47:38
合計ジャッジ時間 5,020 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 100 ms
5,140 KB
testcase_12 AC 96 ms
5,316 KB
testcase_13 AC 114 ms
5,320 KB
testcase_14 AC 112 ms
5,308 KB
testcase_15 AC 109 ms
5,216 KB
testcase_16 AC 110 ms
5,180 KB
testcase_17 AC 111 ms
5,168 KB
testcase_18 AC 42 ms
4,376 KB
testcase_19 AC 80 ms
4,580 KB
testcase_20 AC 49 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 19 ms
4,380 KB
testcase_23 AC 19 ms
4,376 KB
testcase_24 AC 68 ms
4,612 KB
testcase_25 AC 13 ms
4,376 KB
testcase_26 AC 10 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

template <typename T>
vector<int> dijkstra(T &G, int start){
    using P = pair<int, int>;
    int n = G.size();
    vector<int> dis(n, MOD7);
    dis[start] = 0;
    priority_queue<P, vector<P>, greater<P> > Q;
    Q.push({0, start});
    while(!Q.empty()){
        P p = Q.top();
        Q.pop();
        int cur = p.second;
        if(dis[cur] < p.first) continue;
        for(auto e : G[cur]) {
            if(dis[e.second] > dis[cur] + e.first) {
                dis[e.second] = dis[cur] + e.first;
                Q.push({dis[e.second], e.second});
            }
        }
    }
    return dis;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    
    vector<int> x(n + 2), y(n + 2);
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    for(int i = 2; i <= n + 1; i ++) cin >> x[i] >> y[i];

    auto calc = [&](int i, int j, int num) -> int {
        int dis = abs(x[i] - x[j]) + abs(y[i] - y[j]);
        return (dis - 1) / num;
    };
    int le = 0, ri = 100000000;
    while(ri - le > 1) {
        vector<vector<pair<int, int>>> v(n + 2);
        int mid = (ri + le) / 2;
        rep(i, n + 2) rep(j, n + 2) {
            if(i == j) continue;
            v[i].push_back({calc(i, j, mid), j});
        }
        if(dijkstra(v, 0)[1] <= k) ri = mid;
        else le = mid;
    }
    cout << ri << endl;
    
    return 0;
}
0