結果
問題 | No.2354 Poor Sight in Winter |
ユーザー | planes |
提出日時 | 2023-06-16 22:37:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 1,009 bytes |
コンパイル時間 | 2,156 ms |
コンパイル使用メモリ | 175,456 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 15:20:05 |
合計ジャッジ時間 | 3,348 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll =long long; #define all(v) v.begin(),v.end() #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) ll INF=1e18; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N,K;cin>>N>>K; vector<ll> x(N+2),y(N+2); cin>>x[0]>>y[0]; cin>>x[N+1]>>y[N+1]; for(ll i=1;i<=N;i++) cin>>x[i]>>y[i]; ll s=1; ll g=3e5; while(s<g) { ll k=(s+g)/2; priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> S; S.push(make_pair(0,0)); vector<ll> d(N+2,INF); d[0]=0; while(!S.empty()) { auto p=S.top(); S.pop(); if(d[p.second]<p.first) continue; for(ll i=0;i<N+2;i++) { if(i==p.second) continue; ll cost=abs(x[i]-x[p.second])+abs(y[i]-y[p.second]); if(cost%k==0) cost=cost/k-1; else cost/=k; if(p.first+cost<d[i]) { d[i]=p.first+cost; S.push(make_pair(d[i],i)); } } } if(d[N+1]<=K) g=k; else s=k+1; } cout<<s<<endl; }