結果

問題 No.1998 Manhattan Restaurant
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-19 15:53:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,420 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 8,928 KB
最終ジャッジ日時 2023-10-21 01:14:29
合計ジャッジ時間 3,579 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 82 ms
8,928 KB
testcase_16 AC 39 ms
6,288 KB
testcase_17 AC 52 ms
7,608 KB
testcase_18 AC 41 ms
6,552 KB
testcase_19 AC 44 ms
6,816 KB
testcase_20 AC 82 ms
8,928 KB
testcase_21 AC 107 ms
8,928 KB
testcase_22 AC 111 ms
8,928 KB
testcase_23 AC 110 ms
8,928 KB
testcase_24 AC 112 ms
8,928 KB
testcase_25 AC 6 ms
4,348 KB
testcase_26 AC 43 ms
6,816 KB
testcase_27 AC 30 ms
5,760 KB
testcase_28 AC 45 ms
6,816 KB
testcase_29 AC 32 ms
5,760 KB
testcase_30 AC 63 ms
8,400 KB
testcase_31 AC 59 ms
7,872 KB
testcase_32 AC 8 ms
4,348 KB
testcase_33 AC 39 ms
6,288 KB
testcase_34 AC 49 ms
7,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define chmin(x, y) if(x > (y)){ x = (y); }
#define chmax(x, y) if(x < (y)){ x = (y); }
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;

int N;
ll max_x, max_y, min_x, min_y;


bool func(VV<ll>&P, ll k) {
	k *= 2;
	VV<int> block = { {0,0},{0,0} };
	for (auto& p : P) {
		ll x = p[0], y = p[1];
		if ((x < max_x - k and x > min_x + k) or (y < max_y - k and y > min_y + k)) {
			return false;
		}
		if (x < max_x - k and y < max_y - k) {
			block[0][0] = 1;
		}
		if (x > min_x + k and y < max_y - k) {
			block[1][0] = 1;
		}
		if (x < max_x - k and y > min_y + k) {
			block[0][1] = 1;
		}
		if (x > min_x + k and y > min_y + k) {
			block[1][1] = 1;
		}
	}
	if ((block[0][0] | block[1][1]) == 0 or (block[0][1] | block[1][0]) == 0) {
		return true;
	}
	return false;
}


int main(void) {
	cin >> N;
	VV<ll> P(N, V<ll>(2));
	rep(i, 0, N) {
		ll x, y;	cin >> x >> y;
		P[i] = { x + y,x - y };
	}

	max_x = min_x = P[0][0];
	max_y = min_y = P[0][1];
	rep(i, 1, N) {
		chmax(max_x, P[i][0]);	chmax(max_y, P[i][1]);
		chmin(min_x, P[i][0]);	chmin(min_y, P[i][1]);
	}

	ll ok = 2000000001, ng = -1;
	while (ok - ng > 1) {
		ll k = (ok + ng) / 2;
		if (func(P, k)) {
			ok = k;
		}
		else {
			ng = k;
		}
	}

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

	return 0;
}
0