結果

問題 No.2354 Poor Sight in Winter
ユーザー random contestantrandom contestant
提出日時 2023-06-16 22:36:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,666 bytes
コンパイル時間 3,767 ms
コンパイル使用メモリ 266,560 KB
実行使用メモリ 7,632 KB
最終ジャッジ日時 2023-09-06 20:57:23
合計ジャッジ時間 5,379 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 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,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 54 ms
6,956 KB
testcase_12 AC 55 ms
7,172 KB
testcase_13 AC 68 ms
7,632 KB
testcase_14 AC 68 ms
7,456 KB
testcase_15 AC 63 ms
7,312 KB
testcase_16 AC 63 ms
7,336 KB
testcase_17 AC 63 ms
7,516 KB
testcase_18 AC 22 ms
5,524 KB
testcase_19 AC 44 ms
6,516 KB
testcase_20 AC 27 ms
5,616 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 13 ms
4,464 KB
testcase_23 AC 14 ms
4,384 KB
testcase_24 AC 37 ms
6,252 KB
testcase_25 AC 9 ms
4,384 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll,ll>;
#define pb push_back
#define int long long
#define double long double
#define INF (ll) 3e18
// Ctrl + Shift + B コンパイル
// Ctrl + C 中断
// ./m 実行


signed main(){
  int n, k; cin >> n >> k;
  int ok = 1000000;
  int ng = 0;
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  vector<P> xy(n);
  rep(i,n) cin >> xy[i].first >> xy[i].second;
  xy.emplace_back(sx, sy);
  xy.emplace_back(gx, gy);
  
  n = xy.size();
  vector<vector<P>> E(n); // 重み付きグラフへ
  rep(i,n){
    rep(j,n){
      if (i == j) continue;
      E[i].emplace_back(j, abs(xy[i].first-xy[j].first) + abs(xy[i].second-xy[j].second));
    }
  }
  while(ok - ng != 1){
    int mid = (ok + ng) / 2;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.emplace(0, n-2);
    vl dist(n, INF);
    dist[n-2] = 0;
    while(pq.size()){
      auto [cost, now] = pq.top(); pq.pop();
      if (dist[now] != cost) continue;
      for(auto [to, w] : E[now]){
        if (dist[to] <= cost + (w-1) / mid) continue;
        dist[to] = cost + (w-1) / mid;
        pq.emplace(dist[to], to);
      }
    }
    if (dist[n-1] <= k) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}

// 単に明かりを配置すればよいわけではなく
// 例えば k = 2 (0,0) (6,6)なら
// (3,3)においてはダメで、2,2 4,4 と配置する
// Nが小さいので、視界で二分探索すればよいのではないか。
0