結果
問題 | No.2354 Poor Sight in Winter |
ユーザー | FplusFplusF |
提出日時 | 2023-06-16 22:44:07 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 143 ms / 2,000 ms |
コード長 | 2,199 bytes |
コンパイル時間 | 2,666 ms |
コンパイル使用メモリ | 217,024 KB |
実行使用メモリ | 7,556 KB |
最終ジャッジ日時 | 2024-06-24 15:35:51 |
合計ジャッジ時間 | 4,682 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#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'; }