#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
struct point{
int x,y,ind;
};
int n;
vector <point> v;
vector <pair <int,pair <int,int>>> e;
map <int,int> m;
bool srt(point a,point b){
return (a.x+a.y<b.x+b.y);
}
int dist(int i,int j){
int a=abs((v[i].x+v[i].y)-(v[j].x+v[j].y));
int b=abs((v[i].x-v[i].y)-(v[j].x-v[j].y));
return max(a,b);
}
void get_edges(){
sort(v.begin(),v.end(),srt);
m.clear();
for (int i=0;i<n;i++){
auto it=m.lower_bound(v[i].x-v[i].y);
while(it!=m.end()){
int j=(*it).second;
if (v[j].x>v[i].x) break;
it=m.erase(it);
pair <int,pair<int,int>>p;
p.first=dist(i,j);
p.second.first=min(v[i].ind,v[j].ind);
p.second.second=max(v[i].ind,v[j].ind);
e.push_back(p);
}
m[v[i].x-v[i].y]=i;
}
}
void geometry(){
get_edges();
for (int i=0;i<n;i++) v[i].y*=-1;
get_edges();
for (int i=0;i<n;i++) swap(v[i].x,v[i].y);
get_edges();
for (int i=0;i<n;i++) v[i].y*=-1;
get_edges();
}
//------------------------------
int cnt;
vector <int> par(1e5,0);
vector <int> sz(1e5,1);
int holvan(int a){
return (a==par[a]?a:par[a]=holvan(par[a]));
}
void unio(int a,int b){
a=holvan(a);
b=holvan(b);
if (a==b) return;
if (sz[a]>sz[b]) swap(a,b);
par[a]=b;
sz[b]+=sz[a];
cnt--;
}
int spanning_tree(){
cnt=n;
for (int i=0;i<n;i++) par[i]=i;
sort(e.begin(),e.end());
int a,b,w;
for (auto p : e){
a=p.second.first;
b=p.second.second;
w=p.first;
unio(a,b);
if (cnt==1) return w;
}
return -1;
}
//------------------------------
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
v.resize(n);
for (int i=0;i<n;i++){
cin >> v[i].x >> v[i].y;
v[i].ind=i;
}
geometry();
cout << spanning_tree();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 3160 KiB | ||||
2 | Accepted | 263ms | 18492 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 4ms | 4136 KiB | ||||
4 | Accepted | 4ms | 4224 KiB | ||||
5 | Accepted | 4ms | 4448 KiB | ||||
6 | Accepted | 4ms | 4524 KiB | ||||
7 | Accepted | 3ms | 4352 KiB | ||||
subtask3 | 15/15 | ||||||
8 | Accepted | 4ms | 4136 KiB | ||||
9 | Accepted | 4ms | 4224 KiB | ||||
10 | Accepted | 4ms | 4448 KiB | ||||
11 | Accepted | 4ms | 4524 KiB | ||||
12 | Accepted | 3ms | 4352 KiB | ||||
13 | Accepted | 4ms | 4436 KiB | ||||
14 | Accepted | 4ms | 4816 KiB | ||||
15 | Accepted | 4ms | 5052 KiB | ||||
16 | Accepted | 4ms | 5136 KiB | ||||
17 | Accepted | 4ms | 5184 KiB | ||||
subtask4 | 35/35 | ||||||
18 | Accepted | 4ms | 4136 KiB | ||||
19 | Accepted | 4ms | 4224 KiB | ||||
20 | Accepted | 4ms | 4448 KiB | ||||
21 | Accepted | 4ms | 4524 KiB | ||||
22 | Accepted | 3ms | 4352 KiB | ||||
23 | Accepted | 4ms | 4436 KiB | ||||
24 | Accepted | 4ms | 4816 KiB | ||||
25 | Accepted | 4ms | 5052 KiB | ||||
26 | Accepted | 4ms | 5136 KiB | ||||
27 | Accepted | 4ms | 5184 KiB | ||||
28 | Accepted | 4ms | 5160 KiB | ||||
29 | Accepted | 50ms | 8612 KiB | ||||
30 | Accepted | 75ms | 9016 KiB | ||||
31 | Accepted | 75ms | 9356 KiB | ||||
32 | Accepted | 63ms | 11120 KiB | ||||
subtask5 | 35/35 | ||||||
33 | Accepted | 4ms | 4136 KiB | ||||
34 | Accepted | 4ms | 4224 KiB | ||||
35 | Accepted | 4ms | 4448 KiB | ||||
36 | Accepted | 4ms | 4524 KiB | ||||
37 | Accepted | 3ms | 4352 KiB | ||||
38 | Accepted | 4ms | 4436 KiB | ||||
39 | Accepted | 4ms | 4816 KiB | ||||
40 | Accepted | 4ms | 5052 KiB | ||||
41 | Accepted | 4ms | 5136 KiB | ||||
42 | Accepted | 4ms | 5184 KiB | ||||
43 | Accepted | 4ms | 5160 KiB | ||||
44 | Accepted | 50ms | 8612 KiB | ||||
45 | Accepted | 75ms | 9016 KiB | ||||
46 | Accepted | 75ms | 9356 KiB | ||||
47 | Accepted | 63ms | 11120 KiB | ||||
48 | Accepted | 128ms | 12780 KiB | ||||
49 | Accepted | 266ms | 20344 KiB | ||||
50 | Accepted | 266ms | 20668 KiB | ||||
51 | Accepted | 266ms | 20868 KiB | ||||
52 | Accepted | 266ms | 20892 KiB |