結果

問題 No.2354 Poor Sight in Winter
ユーザー Karan AggarwalKaran Aggarwal
提出日時 2023-06-16 22:47:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,898 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 86,592 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-06 21:22:43
合計ジャッジ時間 2,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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