結果

問題 No.2354 Poor Sight in Winter
ユーザー momoyuumomoyuu
提出日時 2023-07-12 15:00:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 2,418 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 150,828 KB
実行使用メモリ 7,692 KB
最終ジャッジ日時 2023-10-12 05:17:08
合計ジャッジ時間 4,577 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 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,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 152 ms
7,448 KB
testcase_12 AC 150 ms
7,416 KB
testcase_13 AC 168 ms
7,380 KB
testcase_14 AC 162 ms
7,692 KB
testcase_15 AC 159 ms
7,376 KB
testcase_16 AC 159 ms
7,480 KB
testcase_17 AC 162 ms
7,572 KB
testcase_18 AC 71 ms
5,444 KB
testcase_19 AC 117 ms
6,624 KB
testcase_20 AC 80 ms
5,764 KB
testcase_21 AC 6 ms
4,352 KB
testcase_22 AC 32 ms
4,352 KB
testcase_23 AC 33 ms
4,348 KB
testcase_24 AC 104 ms
6,516 KB
testcase_25 AC 24 ms
4,348 KB
testcase_26 AC 19 ms
4,352 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<cassert>
#include<cmath>
#include<iomanip>
#include<map>
#include<functional>
//#include<bits/stdc++.h>
using namespace std;
using ll = long long;


template< typename T >
struct edge{
    int from,to;
    T cost;
    edge(int from,int to, T cost):from(from),to(to),cost(cost){};
    edge &operator=(const int& x){
        to = x;
        return *this;
    }
};

template< typename T >
struct graph{
    int n;
    vector<vector<edge<T>>> e;
    graph(int n):n(n),e(n){}

    void addedge(int from,int to,T cost){
        e[from].emplace_back(from,to,cost);
    }

    vector<edge<T>> &operator[](int i) {
        return e[i];
    }
};

/*
 * O(ElogV)
 * 蛻ー驕比ク崎・縺ョ蝣エ蜷医・窶・縺悟・縺」縺ヲ繧九€・ */
template< typename T >
vector<T> dijkstra(graph<T>& g, int st){
    int n = g.n;
    using pt = pair<T,int>;
    vector<T> dist(n,-1);
    dist[st] = 0;
    priority_queue<pt, vector<pt>, greater<pt>>que;
    que.emplace(0,st);
    while(que.size()){
        int ni;
        T cost;
        tie(cost,ni) = que.top();
        que.pop();
        if(dist[ni]<cost&&dist[ni]!=-1) continue;
        for(edge<T> itr:g[ni]){
            int nxt = itr.to;
            if(dist[nxt]>cost+itr.cost||dist[nxt]==-1){
                dist[nxt] = cost + itr.cost;
                que.emplace(dist[nxt],nxt);
            }
        }
    }
    return dist;
};

int main(){
    int n,k,sx,sy,gx,gy;
    cin>>n>>k>>sx>>sy>>gx>>gy;
    vector<int> x(n),y(n);
    for(int i = 0;i<n;i++) cin>>x[i]>>y[i];
    ll right = 1e9;
    ll left = 0;
    while(right-left>1){
        ll mid = (right+left)/2;
        graph<ll> g(n+2);
        int s = n;
        int t = s + 1;
        for(int i = 0;i<n;i++){
            ll now = abs(sx-x[i]) + abs(sy-y[i]) - 1;
            g.addedge(s,i,now/mid);
            now = abs(x[i]-gx) + abs(y[i]-gy) - 1;
            g.addedge(i,t,now/mid);
            for(int j = i + 1;j<n;j++){
                ll now = abs(x[i]-x[j]) + abs(y[i]-y[j]) - 1;
                g.addedge(i,j,now/mid);
                g.addedge(j,i,now/mid);
            }
        }
        ll now = abs(sx-gx) + abs(sy-gy) - 1;
        g.addedge(s,t,now/mid);
        ll can = dijkstra<ll>(g,s)[t];
        if(can<=k) right = mid;
        else left = mid;
    }
    cout<<right<<endl;

}
0