Submission #1832333


Source Code Expand

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 10010
int n, x[2][N], s[N], d;
P xx[2][N];

int bfs(int p0){
	queue<int> q;
	q.push(p0);
	int cnt = 0;
	while(!q.empty()){
		int p = q.front(); q.pop();
		int t = x[s[p]][p];
		rep(i, 2){
			P *l = lower_bound(xx[i], xx[i]+n, P(t-d+1, 0));
			P *r = upper_bound(xx[i], xx[i]+n, P(t+d-1, n));
			//cerr<<(r-l)<<endl;
			while(l<r){
				if(l->snd!=p){
					if(s[l->snd]==i) return -1;
					if(s[l->snd]==-1){
						s[l->snd] = !i;
						cnt++;
						q.push(l->snd);
					}
				}
				l++;
			}
		}
	}
	//cerr<<d<<" "<<p0<<" "<<cnt<<endl;
	return cnt;
}

bool dfs(int p){
	while(p<n && s[p]>=0) p++;
	if(p>=n) return true;
	int s2[N];
	memcpy(s2, s, sizeof(s));
	s[p] = 0;
	int cnt = bfs(p);
	if(cnt==0) return dfs(p+1);
	if(cnt>0 && dfs(p+1)) return true;
	memcpy(s, s2, sizeof(s));
	s[p] = 1;
	if(bfs(p)>=0) return dfs(p+1);
	memcpy(s, s2, sizeof(s));
	s[p] = -1;
	return false;
}

bool solve(){
	mset(s, -1);
	return dfs(0);
}

int main(){
	cin>>n;
	rep(i, n) cin>>x[0][i]>>x[1][i];
	rep(i, n) if(rand()%2) swap(x[0][i], x[1][i]);
	rep(j, 2){
		rep(i, n){
			xx[j][i] = P(x[j][i], i);
		}
		sort(xx[j], xx[j]+n);
	}
	int lb = 0, ub = 1e9/(n-1)+1;
	while(ub-lb>1){
		d = (lb+ub)/2;
		(solve()?lb:ub)=d;
	}
	cout<<lb<<endl;
	return 0;
}

Submission Info

Submission Time
Task F - Flags
User Lepton
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2476 Byte
Status TLE
Exec Time 5259 ms
Memory 196352 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1200
Status
AC × 3
AC × 23
TLE × 7
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 384 KB
00_example_02.txt AC 1 ms 384 KB
00_example_03.txt AC 2 ms 384 KB
01.txt AC 80 ms 1408 KB
02.txt TLE 5255 ms 1024 KB
03.txt AC 3 ms 512 KB
04.txt AC 5 ms 640 KB
05.txt AC 3 ms 512 KB
06.txt TLE 5258 ms 36224 KB
07.txt TLE 5255 ms 2560 KB
08.txt TLE 5255 ms 1536 KB
09.txt AC 126 ms 2048 KB
10.txt AC 4 ms 1152 KB
11.txt AC 2 ms 640 KB
12.txt AC 2 ms 640 KB
13.txt AC 3 ms 896 KB
14.txt TLE 5255 ms 1792 KB
15.txt TLE 5259 ms 47360 KB
16.txt TLE 5259 ms 50432 KB
17.txt AC 13 ms 768 KB
18.txt AC 4 ms 512 KB
19.txt AC 2662 ms 9600 KB
20.txt AC 810 ms 4864 KB
21.txt AC 8 ms 768 KB
22.txt AC 8 ms 768 KB
23.txt AC 11 ms 768 KB
24.txt AC 108 ms 196352 KB
25.txt AC 10 ms 768 KB
26.txt AC 1143 ms 768 KB
27.txt AC 1 ms 384 KB