結果
問題 | No.2354 Poor Sight in Winter |
ユーザー | milanis48663220 |
提出日時 | 2023-06-16 22:20:26 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 196 ms / 2,000 ms |
コード長 | 2,653 bytes |
コンパイル時間 | 1,404 ms |
コンパイル使用メモリ | 126,928 KB |
実行使用メモリ | 5,344 KB |
最終ジャッジ日時 | 2023-09-06 20:28:59 |
合計ジャッジ時間 | 4,329 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 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 | 2 ms
4,376 KB |
testcase_11 | AC | 180 ms
5,196 KB |
testcase_12 | AC | 176 ms
5,196 KB |
testcase_13 | AC | 196 ms
5,256 KB |
testcase_14 | AC | 193 ms
5,228 KB |
testcase_15 | AC | 187 ms
5,344 KB |
testcase_16 | AC | 189 ms
5,252 KB |
testcase_17 | AC | 190 ms
5,284 KB |
testcase_18 | AC | 63 ms
4,380 KB |
testcase_19 | AC | 125 ms
4,688 KB |
testcase_20 | AC | 74 ms
4,380 KB |
testcase_21 | AC | 6 ms
4,376 KB |
testcase_22 | AC | 37 ms
4,380 KB |
testcase_23 | AC | 38 ms
4,380 KB |
testcase_24 | AC | 106 ms
4,388 KB |
testcase_25 | AC | 25 ms
4,376 KB |
testcase_26 | AC | 18 ms
4,380 KB |
testcase_27 | AC | 3 ms
4,376 KB |
testcase_28 | AC | 5 ms
4,380 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; 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; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } // calc ceil(a/b) template<typename T> T ceil_div(T a, T b){ return (a+b-1)/b; } const ll inf = 1e18; using P = pair<ll, ll>; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, k; cin >> n >> k; ll sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; vector<P> ps = {{sx, sy}}; for(int i = 0; i < n; i++){ ll x, y; cin >> x >> y; ps.push_back({x, y}); } ps.push_back({gx, gy}); n = ps.size(); auto d = vec2d(n, n, 0ll); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ auto [xi, yi] = ps[i]; auto [xj, yj] = ps[j]; d[i][j] = abs(xi-xj)+abs(yi-yj); } } auto f = [&](ll x){ vector<ll> dist(n, inf); priority_queue<P, vector<P>, greater<P>> que; auto set_dist = [&](int v, ll d){ if(chmin(dist[v], d)) que.push({d, v}); }; set_dist(0, 0); while(!que.empty()){ auto [dd, v] = que.top(); que.pop(); if(dd != dist[v]) continue; for(int i = 0; i < n; i++){ if(i == v) continue; ll cnt = ceil_div(d[v][i], x)-1; set_dist(i, dd+cnt); } } return dist[n-1] <= k; }; ll l = 0, r = inf; while(r-l > 1){ ll x = (l+r)/2; if(f(x)) { r = x; } else l = x; } cout << r << endl; }