結果
問題 | No.2354 Poor Sight in Winter |
ユーザー |
|
提出日時 | 2023-06-16 22:50:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 2,049 bytes |
コンパイル時間 | 2,089 ms |
コンパイル使用メモリ | 179,504 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 15:45:32 |
合計ジャッジ時間 | 3,670 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> istream& operator >> (istream& is, vector<T>& vec) { for(T& x : vec) is >> x; return is; } template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, k, x, y, gx, gy, x2, y2, d; cin >> n >> k; vector<pair<int,int>> a(n + 2); cin >> x >> y; a[n] = {x, y}; cin >> gx >> gy; a[n + 1] = {gx, gy}; for(int i = 0; i < n; i++){ cin >> x >> y; a[i] = {x, y}; } int ng = -1, ok = 5000000, mid; while(ng + 1 < ok){ mid = (ng + ok) / 2; vector<vector<pair<int,int>>> g(n + 2); for(int i = 0; i < n + 2; i++){ tie(x, y) = a[i]; for(int j = i + 1; j < n + 2; j++){ tie(x2, y2) = a[j]; d = abs(x - x2) + abs(y - y2) - mid; if(d <= 0){ g[i].emplace_back(j, 0); g[j].emplace_back(i, 0); }else if(mid >= 1){ g[i].emplace_back(j, (d + mid - 1) / mid); g[j].emplace_back(i, (d + mid - 1) / mid); } } } vector<int> dp(n + 2, 1 << 30); rpriority_queue<pair<int,int>> pq; pq.emplace(0, n); dp[n] = 0; while(!pq.empty()){ int d, v; tie(d, v) = pq.top(); pq.pop(); if(d > dp[v]) continue; for(auto &&pa : g[v]){ int w, u; tie(u, w) = pa; if(d + w >= dp[u]) continue; dp[u] = d + w; pq.emplace(d + w, u); } } (dp[n + 1] <= k ? ok : ng) = mid; } cout << ok << '\n'; }