結果
| 問題 |
No.2354 Poor Sight in Winter
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-07-12 15:00:21 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 161 ms / 2,000 ms |
| コード長 | 2,418 bytes |
| コンパイル時間 | 1,656 ms |
| コンパイル使用メモリ | 152,832 KB |
| 実行使用メモリ | 7,624 KB |
| 最終ジャッジ日時 | 2024-09-14 04:46:47 |
| 合計ジャッジ時間 | 4,141 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<cassert>
#include<cmath>
#include<iomanip>
#include<map>
#include<functional>
//#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template< typename T >
struct edge{
int from,to;
T cost;
edge(int from,int to, T cost):from(from),to(to),cost(cost){};
edge &operator=(const int& x){
to = x;
return *this;
}
};
template< typename T >
struct graph{
int n;
vector<vector<edge<T>>> e;
graph(int n):n(n),e(n){}
void addedge(int from,int to,T cost){
e[from].emplace_back(from,to,cost);
}
vector<edge<T>> &operator[](int i) {
return e[i];
}
};
/*
* O(ElogV)
* 蛻ー驕比ク崎・縺ョ蝣エ蜷医・窶・縺悟・縺」縺ヲ繧九・ */
template< typename T >
vector<T> dijkstra(graph<T>& g, int st){
int n = g.n;
using pt = pair<T,int>;
vector<T> dist(n,-1);
dist[st] = 0;
priority_queue<pt, vector<pt>, greater<pt>>que;
que.emplace(0,st);
while(que.size()){
int ni;
T cost;
tie(cost,ni) = que.top();
que.pop();
if(dist[ni]<cost&&dist[ni]!=-1) continue;
for(edge<T> itr:g[ni]){
int nxt = itr.to;
if(dist[nxt]>cost+itr.cost||dist[nxt]==-1){
dist[nxt] = cost + itr.cost;
que.emplace(dist[nxt],nxt);
}
}
}
return dist;
};
int main(){
int n,k,sx,sy,gx,gy;
cin>>n>>k>>sx>>sy>>gx>>gy;
vector<int> x(n),y(n);
for(int i = 0;i<n;i++) cin>>x[i]>>y[i];
ll right = 1e9;
ll left = 0;
while(right-left>1){
ll mid = (right+left)/2;
graph<ll> g(n+2);
int s = n;
int t = s + 1;
for(int i = 0;i<n;i++){
ll now = abs(sx-x[i]) + abs(sy-y[i]) - 1;
g.addedge(s,i,now/mid);
now = abs(x[i]-gx) + abs(y[i]-gy) - 1;
g.addedge(i,t,now/mid);
for(int j = i + 1;j<n;j++){
ll now = abs(x[i]-x[j]) + abs(y[i]-y[j]) - 1;
g.addedge(i,j,now/mid);
g.addedge(j,i,now/mid);
}
}
ll now = abs(sx-gx) + abs(sy-gy) - 1;
g.addedge(s,t,now/mid);
ll can = dijkstra<ll>(g,s)[t];
if(can<=k) right = mid;
else left = mid;
}
cout<<right<<endl;
}
momoyuu