結果

問題 No.2354 Poor Sight in Winter
ユーザー tnakao0123tnakao0123
提出日時 2023-06-29 17:02:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 57,336 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 12:17:56
合計ジャッジ時間 2,219 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 32 ms
4,376 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 27 ms
4,376 KB
testcase_17 AC 26 ms
4,376 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 13 ms
4,376 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 14 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 4 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- 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;
}
0