結果

問題 No.2354 Poor Sight in Winter
ユーザー FplusFplusFFplusFplusF
提出日時 2023-06-16 22:44:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 2,199 bytes
コンパイル時間 2,471 ms
コンパイル使用メモリ 214,608 KB
実行使用メモリ 7,440 KB
最終ジャッジ日時 2023-09-06 21:15:04
合計ジャッジ時間 4,425 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 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 104 ms
7,160 KB
testcase_12 AC 97 ms
6,988 KB
testcase_13 AC 119 ms
7,440 KB
testcase_14 AC 118 ms
7,324 KB
testcase_15 AC 111 ms
7,244 KB
testcase_16 AC 118 ms
7,392 KB
testcase_17 AC 107 ms
7,316 KB
testcase_18 AC 49 ms
5,596 KB
testcase_19 AC 84 ms
6,540 KB
testcase_20 AC 51 ms
5,576 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 23 ms
4,380 KB
testcase_23 AC 21 ms
4,376 KB
testcase_24 AC 67 ms
6,184 KB
testcase_25 AC 16 ms
4,376 KB
testcase_26 AC 13 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
using ld=long double;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
struct edge{
    ll to;
	ll cost;
	edge(ll to,ll cost) : to(to),cost(cost) {};
};
struct graph{
    ll v;
    vector<vector<edge>> g;
    vector<ll> d,prev;
    graph(ll n){
        v=n;
        g.resize(v);
        d.resize(v,INF);
        prev.resize(v,-1);
    }
    void add_edge(ll s,ll t,ll cost){
        g[s].push_back({t,cost});
    }
    void dijkstra(ll s){
        rep(i,d.size()){
            d[i]=INF;
        }
        priority_queue<pll,vector<pll>,greater<pll>> pq;
        d[s]=0;
        pq.push({0,s});
        while(!pq.empty()){
            ll x_dist,x_vertex;
            tie(x_dist,x_vertex)=pq.top();
            pq.pop();
            if(d[x_vertex]<x_dist) continue;
            for(auto edge:g[x_vertex]){
                if(d[x_vertex]+edge.cost<d[edge.to]){
                    d[edge.to]=d[x_vertex]+edge.cost;
                    prev[edge.to]=x_vertex;
                    pq.push({d[edge.to],edge.to});
                }
            }
        }
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,k;
    cin >> n >> k;
    ll sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    vector<ll> x(n),y(n);
    rep(i,n) cin >> x[i] >> y[i];
    x.push_back(sx);
    y.push_back(sy);
    x.push_back(gx);
    y.push_back(gy);
    ll ok=2e5,ng=-1;
    while(1<abs(ok-ng)){
        ll mid=(ok+ng)/2;
        graph g(n+2);
        rep(i,n+2){
            rep(j,n+2){
                if(i==j) continue;
                ll d=abs(x[i]-x[j])+abs(y[i]-y[j]);
                if(mid==0){
                    if(d<=mid) g.add_edge(i,j,0);
                }else{
                    g.add_edge(i,j,(d-mid+mid-1)/mid);
                }
            }
        }
        g.dijkstra(n);
        if(g.d[n+1]<=k) ok=mid;
        else ng=mid;
    }
    cout << ok << '\n';
}
0