結果
問題 |
No.2354 Poor Sight in Winter
|
ユーザー |
|
提出日時 | 2023-07-04 21:40:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,177 bytes |
コンパイル時間 | 1,142 ms |
コンパイル使用メモリ | 109,364 KB |
最終ジャッジ日時 | 2025-02-15 06:00:39 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 RE * 3 |
ソースコード
#include<iostream> #include<set> #include<algorithm> #include<vector> #include<string> #include<set> #include<map> #include<numeric> #include<queue> #include<cmath> using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair<int,int> P; typedef pair<int,P> PP; const ll MOD=1e9+7; struct edge{ int to; int cost; edge(int to_,int cost_):to(to_),cost(cost_){}; }; int main(){ int N,K; cin>>N>>K; vector<int> x(N+2),y(N+2); cin>>x[0]>>y[0]>>x[N+1]>>y[N+1]; for(int i=1;i<=N;i++){ cin>>x[i]>>y[i]; } const int inf=1<<30; int ub=inf;//必ず到達が可能 int lb=-1; while(ub-lb>1){ int mid=(ub+lb)/2; //cout<<"mid="<<mid<<endl; vector<vector<edge>> G(N+2); for(int i=0;i<N+2;i++){ for(int j=0;j<N+2;j++){ if(i==j) continue; int dist=abs(x[i]-x[j])+abs(y[i]-y[j]); int c=max((dist+(mid-1))/mid-1,0); G[i].emplace_back(j,c); G[j].emplace_back(i,c); } } //ここからダイクストラ vector<int> dp(N+10,inf);//dp[i]=iに到達するまでにdp[i]個のあかりを消費する priority_queue<P,vector<P>,greater<P>> pq; pq.emplace(0,0); while(!pq.empty()){ auto [d,v]=pq.top(); pq.pop(); if(dp[v]<=d) continue; //dp[v]>d dp[v]=d; for(edge e:G[v]){ if(dp[e.to]>(dp[v]+e.cost)){ pq.emplace(dp[v]+e.cost,e.to); } } } /* for(int i=0;i<=N+2;i++){ cout<<"dp["<<i<<"]="<<dp[i]<<endl; } */ if(dp[N+1]<=K){ //家に到達できる場合 ub=mid; }else{ //家に到達できない lb=mid; } /* if(dp[N+1]>K){ //家に到達できない場合 lb=mid; }else{ //家に到達できる ub=mid; } */ } cout<<ub<<endl; }