結果

問題 No.1998 Manhattan Restaurant
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-19 16:29:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,243 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 85,924 KB
実行使用メモリ 813,740 KB
最終ジャッジ日時 2024-04-15 05:56:16
合計ジャッジ時間 4,952 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 14 ms
10,624 KB
testcase_07 AC 20 ms
12,160 KB
testcase_08 AC 21 ms
12,160 KB
testcase_09 AC 21 ms
12,160 KB
testcase_10 AC 11 ms
7,168 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 16 ms
12,160 KB
testcase_15 MLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
using namespace std;
using ll = long long;
using Pair = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;


bool func(ll N, VV<Pair>& route, ll d) {
	V<ll> c(N);
	rep(v, 0, N) {
		if (c[v]) {
			continue;
		}
		c[v] = 1;
		V<ll> que = { v };
		while (que.empty() == false) {
			ll now = que[que.size() - 1];
			que.pop_back();
			for (auto& r : route[now]) {
				ll nv = r.first, nd = r.second;
				if (nd <= d) {
					continue;
				}
				if (c[nv] == 0) {
					c[nv] = -c[now];
					que.push_back(nv);
				}
				else if (c[nv] == c[now]) {
					return false;
				}
			}
		}
	}
	return true;
}


int main(void) {
	ll N;	cin >> N;
	VV<ll> P(N, V<ll>(2));
	rep(i, 0, N) {
		cin >> P[i][0] >> P[i][1];
	}

	VV<Pair> route(N, V<Pair>(0));
	rep(i, 0, N - 1) {
		rep(j, i + 1, N) {
			ll d = abs(P[i][0] - P[j][0]) + abs(P[i][1] - P[j][1]);
			route[i].push_back({ j,d });
			route[j].push_back({ i,d });
		}
	}

	ll ok = 4000000001, ng = -1;
	while (ok - ng > 1) {
		ll d = (ok + ng) / 2;
		if (func(N, route, d)) {
			ok = d;
		}
		else {
			ng = d;
		}
	}

	ll ans = ok / 2;
	cout << ans << endl;

	return 0;
}
0