結果
問題 | No.2354 Poor Sight in Winter |
ユーザー |
![]() |
提出日時 | 2023-06-16 22:08:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 2,061 bytes |
コンパイル時間 | 4,445 ms |
コンパイル使用メモリ | 262,108 KB |
最終ジャッジ日時 | 2025-02-14 05:56:04 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;typedef int64_t lint;#define rep(i, n) for(int i=0; i<n; i++)#define repx(i, l, n) for(int i=l; i<n; i++)#define all(v) v.begin(), v.end()#define show(x) cout << #x << ": " << x << endl;#define list(x) cout << #x << ": " << x << " ";#define pb push_backusing vi = vector<lint>;using vvi = vector<vector<lint>>;template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }template<class T> inline void drop(T x) { cout << x << endl; exit(0); }template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }constexpr lint LINF = LLONG_MAX/2;using pint = pair<lint, lint>;using vp = vector<pint>;void dijkstra(lint start, vector<lint> &dist, vector<vector<pair<lint, lint>>> &G) {lint a=0, b=0, x, y, N = G.size();dist.resize(N, LINF); dist[start] = 0;priority_queue<pint, vector<pint>, greater<pint>> PQ;PQ.push(make_pair(0, start));while (!PQ.empty()) {tie(x, a) = PQ.top(); PQ.pop();if (dist[a] < x) continue;for (auto p : G[a]) {tie(y, b) = p;if (chmin(dist[b], x+y)) PQ.push(make_pair(x+y, b));}}}vector<vector<pair<lint, lint>>> make_graph(lint N, lint P, vp &g) {vector<vector<pair<lint, lint>>> G(N);lint x, y;rep(i, N) {repx(j, i+1, N) {x = abs(g[i].first-g[j].first)+abs(g[i].second-g[j].second);G[i].pb({(x-1)/P, j});G[j].pb({(x-1)/P, i});}}return G;}int main() {lint N, K;cin >> N >> K;vp g(N+2);lint a=0, b=0, c=0, x, y, z;rep(i, N+2) {cin >> x >> y;g[i] = {x, y};}lint ng = 0, mid, ok = 200100;while (ok-ng > 1) {mid = (ok+ng)/2;vector<vector<pair<lint, lint>>> G = make_graph(N+2, mid, g);vi d;dijkstra(0, d, G);if (d[1] <= K) ok = mid;else ng = mid;}std::cout << ok << '\n';}