結果

問題 No.1998 Manhattan Restaurant
ユーザー 👑 Nachia
提出日時 2022-07-01 21:25:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 76,600 KB
最終ジャッジ日時 2025-01-30 02:14:53
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using i64 = long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N; cin >> N;
	vector<i64> X(N);
	vector<i64> Y(N);
	rep(i,N){
		int x,y; cin >> x >> y;
		X[i] = x+y; Y[i] = x-y;
	}

	i64 minX = X[0], maxX = X[0];
	i64 minY = Y[0], maxY = Y[0];
	rep(i, N){
		minX = min(minX, X[i]);
		maxX = max(maxX, X[i]);
		minY = min(minY, Y[i]);
		maxY = max(maxY, Y[i]);
	}
	for(auto& x : X) x -= minX;
	maxX -= minX;
	for(auto& y : Y) y -= minY;
	maxY -= minY;

	i64 ans = 1001001001001;

	rep(t,2){
		for(auto& x : X) x = maxX - x;
		i64 tmp = 0;
		rep(i,N){
			i64 cost1 = max(X[i], Y[i]);
			i64 cost2 = max(maxX - X[i], maxY - Y[i]);
			tmp = max(tmp, min(cost1,cost2));
		}
		ans = min(ans, tmp);
	}
    
    ans = (ans + 1) / 2;
	cout << ans << '\n';
	return 0;
}
0