結果

問題 No.2354 Poor Sight in Winter
ユーザー simansiman
提出日時 2023-06-19 16:33:37
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,585 bytes
コンパイル時間 3,422 ms
コンパイル使用メモリ 104,260 KB
実行使用メモリ 5,208 KB
最終ジャッジ日時 2023-09-09 11:55:10
合計ジャッジ時間 5,448 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int N, K;
int SX, SY, GX, GY;
int X[510];
int Y[510];

struct Node {
  int id;
  int k;

  Node(int id = -1, int k = -1) {
    this->id = id;
    this->k = k;
  }

  bool operator>(const Node &n) const {
    return k < n.k;
  }
};

bool f(int P) {
  priority_queue <Node, vector<Node>, greater<Node>> pque;
  pque.push(Node(0, K));
  bool visited[N + 2];
  memset(visited, false, sizeof(visited));

  while (not pque.empty()) {
    Node node = pque.top();
    pque.pop();
    int x = X[node.id];
    int y = Y[node.id];

    if (visited[node.id]) continue;
    visited[node.id] = true;

    if (node.id == N + 1) {
      return true;
    }

    for (int i = 1; i <= N + 1; ++i) {
      if (visited[i]) continue;

      int nx = X[i];
      int ny = Y[i];
      int dist = abs(y - ny) + abs(x - nx);
      int cost = (dist <= P) ? 0 : (dist - 1) / P;
      if (node.k < cost) continue;

      pque.push(Node(i, node.k - cost));
    }
  }

  return false;
}

int main() {
  cin >> N >> K;
  cin >> SX >> SY >> GX >> GY;
  for (int i = 1; i <= N; ++i) {
    cin >> X[i] >> Y[i];
  }
  X[0] = SX;
  Y[0] = SY;
  X[N + 1] = GX;
  Y[N + 1] = GY;

  int ok = 100000000;
  int ng = 0;

  while (abs(ok - ng) >= 2) {
    int p = (ok + ng) / 2;

    if (f(p)) {
      ok = p;
    } else {
      ng = p;
    }
  }

  cout << ok << endl;

  return 0;
}
0