結果
| 問題 |
No.2354 Poor Sight in Winter
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-16 22:47:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,898 bytes |
| コンパイル時間 | 951 ms |
| コンパイル使用メモリ | 87,444 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-24 15:42:27 |
| 合計ジャッジ時間 | 1,991 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
// WEBLINK
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vii = vector<ii>;
using viii = vector<iii>;
#define pb push_back
#define fst first
#define snd second
#define all(x) (x).begin,(x).end()
template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;}
template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;}
// ---------- DEBUG --------------------
// #define ON_PC
#ifdef ON_PC
#include </Users/karanaggarwal/code/debug.h>
#else
#define deb(x...)
#endif
///////////////////////////////////
void inp(ii & x)
{
cin >> x.fst >> x.snd;
}
int dis(ii x, ii y)
{
return abs(x.fst - y.fst) + abs(x.snd - y.snd);
}
int fw(ii x, ii y, int d)
{
return (dis(x, y) - 1) / d;
}
int djk(vii & A, int m)
{
const int inf = 10000000;
int n = A.size();
vi D(n, inf);
vector<bool> E(n);
D[0] = 0;
priority_queue<ii> Q;
Q.push({0, 0});
deb(m);
while (!Q.empty())
{
auto p = Q.top(); Q.pop();
int x = p.second;
if (E[x] or - p.first > D[x]) continue;
E[x] = true;
if (x == n - 1) return D[x];
for (int y = 0; y < n; y++)
{
if (E[y] == false)
{
int nd = D[x] + fw(A[x], A[y], m);
if (nd < D[y])
{
D[y] = nd;
Q.push({ -nd, y});
}
}
}
}
return D[n - 1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k; cin >> n >> k;
vii A(n + 2);
inp(A[0]); inp(A[n + 1]);
for (int i = 1; i <= n; i++)
inp(A[i]);
int l = 1; int h = dis(A.front(), A.back());
while (h > l)
{
int m = (l + h) / 2;
int ret = djk(A, m);
deb(l, h, m, ret, k);
if (ret <= k) h = m;
else l = m + 1;
}
cout << l << endl;
return 0;
}