結果
問題 | No.2354 Poor Sight in Winter |
ユーザー |
![]() |
提出日時 | 2023-06-29 17:02:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 1,238 bytes |
コンパイル時間 | 480 ms |
コンパイル使用メモリ | 57,988 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-06 07:37:51 |
合計ジャッジ時間 | 1,725 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
/* -*- coding: utf-8 -*-** 2354.cc: No.2354 Poor Sight in Winter - yukicoder*/#include<cstdio>#include<queue>#include<algorithm>#include<utility>using namespace std;/* constant */const int MAX_N = 502;const int INF = 1 << 30;/* typedef */typedef pair<int,int> pii;/* global variables */int xs[MAX_N], ys[MAX_N], ds[MAX_N];/* subroutines */inline int mdist(int i, int j) {return abs(xs[j] - xs[i]) + abs(ys[j] - ys[i]);}int calc(int n, int p) {fill(ds, ds + n, INF);ds[0] = 0;priority_queue<pii> q;q.push(pii(0, 0));while (! q.empty()) {auto ue = q.top(); q.pop();int ud = -ue.first, u = ue.second;if (ds[u] != ud) continue;if (u == 1) break;for (int v = 0; v < n; v++)if (u != v) {int vd = ud + (mdist(u, v) - 1) / p;if (ds[v] > vd) {ds[v] = vd;q.push(pii(-vd, v));}}}return ds[1];}/* main */int main() {int n, k;scanf("%d%d%d%d%d%d", &n, &k, xs, ys, xs + 1, ys + 1);n += 2;for (int i = 2; i < n; i++) scanf("%d%d", xs + i, ys + i);int p0 = 0, p1 = 200000;while (p0 + 1 < p1) {int p = (p0 + p1) / 2;if (calc(n, p) <= k) p1 = p;else p0 = p;}printf("%d\n", p1);return 0;}