結果

問題 No.2436 Min Diff Distance
ユーザー 沙耶花沙耶花
提出日時 2023-08-18 23:23:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 439 ms / 2,000 ms
コード長 1,741 bytes
コンパイル時間 4,810 ms
コンパイル使用メモリ 270,660 KB
実行使用メモリ 29,168 KB
最終ジャッジ日時 2024-05-06 06:08:03
合計ジャッジ時間 10,488 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 394 ms
29,040 KB
testcase_04 AC 386 ms
29,040 KB
testcase_05 AC 390 ms
29,036 KB
testcase_06 AC 398 ms
29,040 KB
testcase_07 AC 439 ms
29,168 KB
testcase_08 AC 395 ms
29,028 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 292 ms
29,040 KB
testcase_12 AC 221 ms
29,168 KB
testcase_13 AC 262 ms
26,048 KB
testcase_14 AC 37 ms
6,476 KB
testcase_15 AC 368 ms
28,880 KB
testcase_16 AC 165 ms
15,944 KB
testcase_17 AC 336 ms
27,800 KB
testcase_18 AC 294 ms
26,916 KB
testcase_19 AC 336 ms
27,884 KB
testcase_20 AC 217 ms
17,368 KB
testcase_21 AC 91 ms
10,004 KB
testcase_22 AC 38 ms
6,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

using P = pair<long long,long long>;
P op(P a,P b){
	return make_pair(min(a.first,b.first),max(a.second,b.second));
}
P e(){
	return make_pair(Inf64,-Inf64);
}

int main(){
	
	int n;
	cin>>n;
	vector<pair<long long,long long>> p(n);
	rep(i,n){
		cin>>p[i].first>>p[i].second;
	}
	sort(p.begin(),p.end());
	
	
	long long ans = Inf64;
	vector<long long> Ms(n,-Inf64),ms(n,Inf64);
	{
		segtree<P,op,e> seg0(n+5),seg1(n+5);
		rep(i,n){
			long long x = p[i].first;
			long long y = p[i].second;
			
			long long m = x,M = x;
			m += min(y + seg0.prod(0,y).first, seg1.prod(y,n+5).first - y);
			M += max(y + seg0.prod(0,y).second, seg1.prod(y,n+5).second - y);
			Ms[i] = max(Ms[i],M);
			ms[i] = min(ms[i],m);
			//cout<<x<<','<<y<<' '<<m<<' '<<M<<endl;
			//ans = min(ans,M-m);
			seg0.set(y,op(seg0.get(y), make_pair(-x-y,-x-y)));
			seg1.set(y,op(seg1.get(y), make_pair(-x+y,-x+y)));
		}
	}
	
	{
		segtree<P,op,e> seg0(n+5),seg1(n+5);
		for(int i=n-1;i>=0;i--){
			long long x = p[i].first;
			long long y = p[i].second;
			
			long long m = -x,M = -x;
			m += min(y + seg0.prod(0,y).first, seg1.prod(y,n+5).first - y);
			M += max(y + seg0.prod(0,y).second, seg1.prod(y,n+5).second - y);
			Ms[i] = max(Ms[i],M);
			ms[i] = min(ms[i],m);
			//cout<<x<<','<<y<<' '<<m<<' '<<M<<endl;
			//ans = min(ans,M-m);
			seg0.set(y,op(seg0.get(y), make_pair(x-y,x-y)));
			seg1.set(y,op(seg1.get(y), make_pair(x+y,x+y)));
		}
	}
	rep(i,n)ans = min(ans,Ms[i]-ms[i]);
	cout<<ans<<endl;
	
	
	return 0;
}
0