結果

問題 No.2354 Poor Sight in Winter
ユーザー kabipoyokabipoyo
提出日時 2023-06-16 22:08:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,061 bytes
コンパイル時間 3,964 ms
コンパイル使用メモリ 271,088 KB
実行使用メモリ 7,684 KB
最終ジャッジ日時 2023-09-06 20:05:27
合計ジャッジ時間 5,987 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 87 ms
7,280 KB
testcase_12 AC 93 ms
7,228 KB
testcase_13 AC 113 ms
7,432 KB
testcase_14 AC 109 ms
7,412 KB
testcase_15 AC 98 ms
7,476 KB
testcase_16 AC 99 ms
7,684 KB
testcase_17 AC 100 ms
7,496 KB
testcase_18 AC 42 ms
5,388 KB
testcase_19 AC 71 ms
6,712 KB
testcase_20 AC 52 ms
5,744 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 22 ms
4,384 KB
testcase_23 AC 22 ms
4,384 KB
testcase_24 AC 67 ms
6,344 KB
testcase_25 AC 15 ms
4,380 KB
testcase_26 AC 12 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
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; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;
using pint = pair<lint, lint>;
using vp = vector<pint>;

void dijkstra(lint start, vector<lint> &dist, vector<vector<pair<lint, lint>>> &G) {
	lint a=0, b=0, x, y, N = G.size();
	dist.resize(N, LINF); dist[start] = 0;
	priority_queue<pint, vector<pint>, greater<pint>> PQ;
	PQ.push(make_pair(0, start));
	while (!PQ.empty()) {
		tie(x, a) = PQ.top(); PQ.pop();
		if (dist[a] < x) continue;
		for (auto p : G[a]) {
			tie(y, b) = p;
			if (chmin(dist[b], x+y)) PQ.push(make_pair(x+y, b));
		}
	}
}

vector<vector<pair<lint, lint>>> make_graph(lint N, lint P, vp &g) {
	vector<vector<pair<lint, lint>>> G(N);
	lint x, y;
	rep(i, N) {
		repx(j, i+1, N) {
			x = abs(g[i].first-g[j].first)+abs(g[i].second-g[j].second);
			G[i].pb({(x-1)/P, j});
			G[j].pb({(x-1)/P, i});
		}
	}
	return G;
}

int main() {
	lint N, K;
	cin >> N >> K;
	vp g(N+2);

	lint a=0, b=0, c=0, x, y, z;
	rep(i, N+2) {
		cin >> x >> y;
		g[i] = {x, y};
	}
	lint ng = 0, mid, ok = 200100;
	while (ok-ng > 1) {
		mid = (ok+ng)/2;
		vector<vector<pair<lint, lint>>> G = make_graph(N+2, mid, g);
		vi d;
		dijkstra(0, d, G);
		if (d[1] <= K) ok = mid;
		else ng = mid;
	}
	std::cout << ok << '\n';
}
0