結果

問題 No.1998 Manhattan Restaurant
ユーザー 👑 kmjpkmjp
提出日時 2022-07-01 23:00:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,058 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 211,560 KB
実行使用メモリ 25,512 KB
最終ジャッジ日時 2023-08-17 10:37:23
合計ジャッジ時間 6,662 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 34 ms
4,376 KB
testcase_07 AC 33 ms
4,380 KB
testcase_08 AC 33 ms
4,376 KB
testcase_09 AC 32 ms
4,376 KB
testcase_10 AC 25 ms
4,380 KB
testcase_11 AC 15 ms
4,380 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 37 ms
4,376 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


ll N;
ll X[101010],Y[101010];

int ok(ll v) {
	vector<pair<ll,ll>> ev;
	multiset<ll> X1,Y1,X2,Y2;
	ll miy=1LL<<60;
	int i;
	FOR(i,N) miy=min(miy,Y[i]);
	FOR(i,N) {
		X1.insert(X[i]);
		Y1.insert(Y[i]);
		if(Y[i]-miy<=v) {
			ev.push_back({X[i],i});
			ev.push_back({X[i]+v,i+N});
		}
	}
	sort(ALL(ev));
	FORR2(x,i,ev) {
		if(i<N) {
			X1.erase(X1.find(X[i]));
			Y1.erase(Y1.find(Y[i]));
			X2.insert(X[i]);
			Y2.insert(Y[i]);
		}
		else {
			i-=N;
			X2.erase(X2.find(X[i]));
			Y2.erase(Y2.find(Y[i]));
			X1.insert(X[i]);
			Y1.insert(Y[i]);
		}
		ll ma=0;
		if(X1.size()) ma=max({ma,*X1.rbegin()-*X1.begin(),*Y1.rbegin()-*Y1.begin()});
		if(X2.size()) ma=max({ma,*X2.rbegin()-*X2.begin(),*Y2.rbegin()-*Y2.begin()});
		if(ma<=v) return 1;
	}
	return 0;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll xma=-1LL<<60,xmi=1LL<<60,yma=-1LL<<60,ymi=1LL<<60;
	FOR(i,N) {
		cin>>x>>y;
		X[i]=x+y;
		Y[i]=x-y;
		xma=max(xma,X[i]);
		xmi=min(xmi,X[i]);
		yma=max(yma,Y[i]);
		ymi=min(ymi,Y[i]);
	}
	
	if(N<=2) {
		cout<<0<<endl;
		return;
	}
	
	
	ll ret=(xma-xmi)+(yma-ymi);
	FOR(k,2) {
		
		ll can=1LL<<40;
		for(j=39;j>=0;j--) if(ok(can-(1LL<<j))) can-=1LL<<j;
		ret=min(ret,can);
		
		
		
		FOR(i,N) swap(X[i],Y[i]);
	}
	cout<<ret/2<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0