結果

問題 No.1997 X Lighting
ユーザー MasKoaTSMasKoaTS
提出日時 2022-02-21 17:40:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,250 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 83,412 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-04-28 12:00:11
合計ジャッジ時間 4,734 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

//TLE

#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