結果
| 問題 |
No.2354 Poor Sight in Winter
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2023-06-17 06:29:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 145 ms / 2,000 ms |
| コード長 | 2,197 bytes |
| コンパイル時間 | 2,382 ms |
| コンパイル使用メモリ | 210,744 KB |
| 最終ジャッジ日時 | 2025-02-14 22:10:44 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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-1)/mid-1);
}
}
}
g.dijkstra(n);
if(g.d[n+1]<=k) ok=mid;
else ng=mid;
}
cout << ok << '\n';
}
FplusFplusF