Submission #1118369


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100100;

pair<int, int> A[MAX];

vector<pair<int, int> > E;

vector<int> g[MAX];
vector<int> gr[MAX];

void add_edge(int x, int y)
{
	g[x].PB(y);
	gr[y].PB(x);
}

struct RHQ
{
	int n;
	int shift;
	int mx;

	void init(int tl, int tr, int v, vector<pair<int, int> > &E)
	{
		if (tl == tr)
		{
			mx = max(mx, v + shift + 1);
			add_edge(v + shift, E[tl].second);
			return;
		}

		int tm = (tl + tr) / 2;
		init(tl, tm, v*2, E);
		init(tm+1, tr, v*2+1, E);
		add_edge(v + shift, 2*v + shift);
		add_edge(v + shift, 2*v+1 + shift);
	}

	void init(vector<pair<int, int> >& E, int shift)
	{
		this->shift = shift;
		n = SZ(E);
		mx = 0;

		init(0, n-1, 1, E);
	}

	void add(int tl, int tr, int v, int l, int r, int x)
	{
	//	cout<<tl<<' '<<tr<<' '<<v<<' '<<l<<' '<<r<<' '<<x<<endl;
		if (tl == l && tr == r)
		{
			add_edge(x, v + shift);
			return;
		}
		if (l > r) return;

		int tm = (tl + tr) / 2;

		add(tl, tm, v*2, l, min(r, tm), x);
		add(tm+1, tr, v*2+1, max(l, tm + 1), r, x);
	}

	void add(int x, int L, int R)
	{
		add(0, n-1, 1, L, R, x);
	//	cout<<endl;
	}
} H;

int N;
int n;

bool U[MAX];
int C[MAX];
vector<int> ord;

void dfs1(int x)
{
	U[x] = true;
	FOR (i, 0, SZ(g[x]))
	{
		int to = g[x][i];
		if (U[to]) continue;
		dfs1(to);
	}

	ord.PB(x);
}

void dfs2(int x, int c)
{
	U[x] = true;
	C[x] = c;

	FOR (i, 0, SZ(gr[x]))
	{
		int to = gr[x][i];
		if (U[to]) continue;
		dfs2(to, c);
	}
}


bool can(int m)
{
	FOR (i, 0, N)
	{
		g[i].clear();
		gr[i].clear();
		U[i] = false;
	}

	ord.clear();

	H.init(E, 2*n);

	N = H.mx;

	/*FOR (i, 0, SZ(E))
	{
		cout<<E[i].first<<' '<<E[i].second<<endl;
	}
	cout<<endl;*/

	FOR (i, 0, SZ(E))
	{
		int p = E[i].first;
		int x = E[i].second;
		if (x < n) x += n;
		else x -= n;

		int pos = upper_bound(ALL(E), MP(p + m-1, INF)) - E.begin() - 1;

		H.add(x, i+1, pos);
		//cout<<i<<' '<<x<<' '<<pos<<' ';

		pos = upper_bound(ALL(E), MP(p - m , INF)) - E.begin();
		//cout<<pos<<endl;
		H.add(x, pos, i-1);
	}


	FOR (i, 0, N)
	{
		if (!U[i]) dfs1(i);
	}

	reverse(ALL(ord));
	FOR (i, 0, N)
	{
		U[i] = false;
	}

	int cnt = 0;
	FOR (i, 0, N)
	{
		int x = ord[i];
		if (!U[x])
		{
			dfs2(x, cnt);
			cnt++;
		}
	}
/*
	cout<<N<<endl;
	FOR (i, 0, N)
	{
		cout<<i<<": "<<endl;
		FOR (j, 0, SZ(g[i]))
		{
			int to = g[i][j];
			cout<<to<<' ';
		}
		cout<<endl;
	}*/

	//exit(0);

	FOR (i, 0, n)
	{
		if (C[i] == C[i+n]) return false;
	}
	return true;

}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	scanf("%d", &n);
	FOR (i, 0, n)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		A[i] = MP(x, y);
		E.PB(MP(x, i));
		E.PB(MP(y, i+n));
	}

	sort(ALL(E));


	int L = 0, R = INF;
	while(R - L > 1)
	{
		int m = (R + L) / 2;
		if (can(m)) L = m;
		else R = m;
	}

	cout<<L<<endl;

}

Submission Info

Submission Time
Task F - Flags
User Andrew_Makar
Language C++14 (GCC 5.4.1)
Score 1200
Code Size 3591 Byte
Status AC
Exec Time 911 ms
Memory 23928 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:213:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:217:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y);
                        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1200 / 1200
Status
AC × 3
AC × 30
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 3 ms 4992 KB
00_example_02.txt AC 3 ms 4992 KB
00_example_03.txt AC 3 ms 4992 KB
01.txt AC 15 ms 5504 KB
02.txt AC 7 ms 5120 KB
03.txt AC 4 ms 4992 KB
04.txt AC 4 ms 4992 KB
05.txt AC 5 ms 4992 KB
06.txt AC 436 ms 20472 KB
07.txt AC 432 ms 20472 KB
08.txt AC 505 ms 20600 KB
09.txt AC 15 ms 5376 KB
10.txt AC 7 ms 5120 KB
11.txt AC 4 ms 4992 KB
12.txt AC 4 ms 4992 KB
13.txt AC 5 ms 4992 KB
14.txt AC 466 ms 18168 KB
15.txt AC 445 ms 18168 KB
16.txt AC 440 ms 18168 KB
17.txt AC 16 ms 5376 KB
18.txt AC 8 ms 5120 KB
19.txt AC 496 ms 19960 KB
20.txt AC 514 ms 19832 KB
21.txt AC 630 ms 20216 KB
22.txt AC 699 ms 20344 KB
23.txt AC 911 ms 23928 KB
24.txt AC 616 ms 21752 KB
25.txt AC 617 ms 23032 KB
26.txt AC 539 ms 21368 KB
27.txt AC 3 ms 4992 KB