結果
| 問題 |
No.1998 Manhattan Restaurant
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2022-07-01 23:02:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,065 bytes |
| コンパイル時間 | 2,419 ms |
| コンパイル使用メモリ | 209,228 KB |
| 最終ジャッジ日時 | 2025-01-30 03:29:45 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 13 TLE * 18 |
ソースコード
#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];
vector<pair<ll,ll>> ev;
multiset<ll> X1,Y1,X2,Y2;
int ok(ll v) {
ev.clear();
X1.clear();
X2.clear();
Y2.clear();
Y1.clear();
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);
ll can=1LL<<33;
for(j=32;j>=0;j--) if(ok(can-(1LL<<j))) can-=1LL<<j;
ret=min(ret,can);
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;
}
kmjp