結果

問題 No.2612 Close the Distance
ユーザー 👑 kmjpkmjp
提出日時 2024-01-21 00:08:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,059 ms / 3,000 ms
コード長 1,935 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 208,684 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-21 00:08:52
合計ジャッジ時間 18,186 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 596 ms
6,676 KB
testcase_07 AC 486 ms
6,676 KB
testcase_08 AC 436 ms
6,676 KB
testcase_09 AC 568 ms
6,676 KB
testcase_10 AC 487 ms
6,676 KB
testcase_11 AC 583 ms
6,676 KB
testcase_12 AC 521 ms
6,676 KB
testcase_13 AC 602 ms
6,676 KB
testcase_14 AC 548 ms
6,676 KB
testcase_15 AC 579 ms
6,676 KB
testcase_16 AC 859 ms
6,676 KB
testcase_17 AC 1,043 ms
6,676 KB
testcase_18 AC 1,004 ms
6,676 KB
testcase_19 AC 1,059 ms
6,676 KB
testcase_20 AC 711 ms
6,676 KB
testcase_21 AC 956 ms
6,676 KB
testcase_22 AC 650 ms
6,676 KB
testcase_23 AC 708 ms
6,676 KB
testcase_24 AC 792 ms
6,676 KB
testcase_25 AC 1,053 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

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;}
//-------------------------------------------------------

int N;
ll X[202020],Y[202020];

int ok(ll v, vector<pair<ll,ll>> V) {
	ll Xma=-1LL<<60;
	ll Xmi=1LL<<60;
	ll Yma=-1LL<<60;
	ll Ymi=1LL<<60;
	int i;
	FOR(i,N) {
		int n=0;
		FORR2(a,b,V) if(a<=X[i]&&X[i]<=a+v&&b<=Y[i]&&Y[i]<=b+v) n=1;
		if(n==0) {
			Xmi=min(Xmi,X[i]);
			Xma=max(Xma,X[i]-v);
			Ymi=min(Ymi,Y[i]);
			Yma=max(Yma,Y[i]-v);
		}
	}
	if(Xmi==1LL<<60) return 1;
	if(V.size()==3) return 0;
	if(V.size()==0) {
		V.push_back({Xmi,Ymi});
		if(ok(v,V)) return 1;
		V.pop_back();
		V.push_back({Xmi,Yma});
		if(ok(v,V)) return 1;
		V.pop_back();
		V.push_back({Xma,Ymi});
		if(ok(v,V)) return 1;
		V.pop_back();
		V.push_back({Xma,Yma});
		if(ok(v,V)) return 1;
		V.pop_back();
	}
	else {
		V.push_back({Xmi,Ymi});
		V.push_back({Xma,Yma});
		if(ok(v,V)) return 1;
		V.pop_back();
		V.pop_back();
		V.push_back({Xma,Ymi});
		V.push_back({Xmi,Yma});
		if(ok(v,V)) return 1;
		V.pop_back();
		V.pop_back();
	}
	return 0;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x>>y;
		X[i]=x+y;
		Y[i]=x-y;
	}
	ll ret=(1LL<<31)-1;
	for(i=30;i>=0;i--) if(ok(ret-(1LL<<i),{})) ret-=1LL<<i;
	cout<<ret<<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