結果
問題 | No.2354 Poor Sight in Winter |
ユーザー |
![]() |
提出日時 | 2023-06-17 03:44:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 138 ms / 2,000 ms |
コード長 | 1,626 bytes |
コンパイル時間 | 2,318 ms |
コンパイル使用メモリ | 209,028 KB |
最終ジャッジ日時 | 2025-02-14 22:01:49 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const ll INF=1LL<<60; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector<vector<Edge>>; using pli=pair<ll,int>; template<class T> bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } vector<ll> dijkstra(int s,Graph &G){ int n=G.size(); vector<ll> dist(n,INF); dist[s]=0; priority_queue<pli,vector<pli>,greater<pli>> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } return dist; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,k; cin>>n>>k; int sx,sy,gx,gy; cin>>sx>>sy>>gx>>gy; vector<int> X(n+2),Y(n+2); X[0]=sx,Y[0]=sy; rep(i,n) cin>>X[i+1]>>Y[i+1]; X[n+1]=gx,Y[n+1]=gy; vector<vector<int>> D(n+2,vector<int>(n+2)); rep(i,n+2){ rep(j,n+2) D[i][j]=abs(X[i]-X[j])+abs(Y[i]-Y[j]); } auto f=[&](int x)->int{ Graph G(n+2); rep(i,n+2){ for(int j=i+1;j<n+2;j++){ int d=(D[i][j]-1)/x; G[i].push_back(Edge(j,d)); G[j].push_back(Edge(i,d)); } } vector<ll> dis=dijkstra(0,G); return dis[n+1]; }; int ok=200010,ng=0; while(ok-ng>1){ int mid=(ok+ng)/2; if(f(mid)<=k) ok=mid; else ng=mid; } cout<<ok<<endl; return 0; }