結果

問題 No.2436 Min Diff Distance
ユーザー shobonvipshobonvip
提出日時 2023-08-11 21:04:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,050 ms / 2,000 ms
コード長 2,281 bytes
コンパイル時間 4,862 ms
コンパイル使用メモリ 271,232 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2024-04-29 12:23:11
合計ジャッジ時間 18,807 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1,050 ms
18,560 KB
testcase_04 AC 995 ms
18,560 KB
testcase_05 AC 1,022 ms
18,560 KB
testcase_06 AC 1,035 ms
18,556 KB
testcase_07 AC 1,048 ms
18,560 KB
testcase_08 AC 1,024 ms
18,560 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 397 ms
18,688 KB
testcase_12 AC 396 ms
18,560 KB
testcase_13 AC 628 ms
16,256 KB
testcase_14 AC 85 ms
5,480 KB
testcase_15 AC 975 ms
18,352 KB
testcase_16 AC 410 ms
10,672 KB
testcase_17 AC 879 ms
17,436 KB
testcase_18 AC 762 ms
17,024 KB
testcase_19 AC 860 ms
17,756 KB
testcase_20 AC 543 ms
11,776 KB
testcase_21 AC 216 ms
7,396 KB
testcase_22 AC 84 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

typedef pair<int,int> S;

S op(S a, S b){
	if (a.first < b.first){
		return a;
	}
	return b;
}

S e(){
	return pair((int)1e9, -1);
}

int main(){
	int n; cin >> n;
	vector<int> x(n), y(n);
	rep(i,0,n) cin >> x[i] >> y[i];

	vector<int> mindist(n, 1e9);

	rep(i,0,2){
		rep(j,0,2){
			rep(k,0,2){
				vector<pair<int,int>> d(n);
				segtree<S, op, e> seg(2*n + 1);
				rep(l,0,n) d[l] = pair(y[l] - x[l], l);
				sort(d.begin(), d.end());
				rep(l,0,n){
					int s = d[l].second;
					S r = seg.prod(y[s] + n, 2*n+1);
					if (r.second != -1){
						chmin(mindist[r.second], abs(x[s] + y[s] - r.first));
						chmin(mindist[s], abs(x[s] + y[s] - r.first));
					}
					seg.set(y[s] + n, op(seg.get(y[s] + n), pair(x[s] + y[s], s)));
				}
				swap(x, y);
			}
			rep(l,0,n) x[l] = - x[l];
		}
		rep(l,0,n) y[l] = - y[l];
	}

	vector<int> a(n), b(n);
	rep(i,0,n){
		a[i] = x[i] + y[i];
		b[i] = x[i] - y[i];
	}
	
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	
	int ans = 1e9;

	rep(i,0,n){
		int tmp = 0;
		chmax(tmp, abs(a[n-1] - (x[i] + y[i])));
		chmax(tmp, abs(a[0] - (x[i] + y[i])));
		chmax(tmp, abs(b[n-1] - (x[i] - y[i])));
		chmax(tmp, abs(b[0] - (x[i] - y[i])));
		chmin(ans, tmp - mindist[i]);
	}
	
	cout << ans << '\n';
}

0