Submission #1119256


Source Code Expand

#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 40010, B = N * 8, M = N * 20;
int n, x[N], y[N];
 
struct edge{ int to, pre; }e[N * 2 * 40]; int u[M], l = 0;
void ins(int a, int b) { e[++l] = (edge){b, u[a]}, u[a] = l; }
#define v e[i].to
#define reg(i,a) for(int i = u[a]; i; i = e[i].pre)
void add(int a, int b) { ins(a, b), ins(b^1, a^1); }
 
pair<int, int> nd[N * 2];
#define mid ((l + r) >> 1)
#define lc (x << 1)
#define rc (lc | 1)
#define lcq lc, l, mid
#define rcq rc, mid + 1, r
void build(int x, int l, int r) {
	if (l == r) 
		add(x << 1, nd[l].second ^ 1); 
	else 
		build(lcq), build(rcq), 
		add(x << 1, lc << 1), add(x << 1, rc << 1);
}
 
int a, b, c;
 
void modi(int x, int l, int r) {
	if (a <= l && r <= b) add(c, x << 1);
	else {
		if (a <= mid) modi(lcq); 
		if (b >  mid) modi(rcq);
	}
}
 
int pre[M], low[M], dfn = 0; 
int st[M], top = 0, cnt = 0, scc[M];
void dfs(int x) {
	pre[x] = low[x] = ++dfn; st[top++] = x;
	reg(i,x) if (!pre[v]) dfs(v), low[x] = min(low[x], low[v]);
	else if (!scc[v]) low[x] = min(low[x], pre[v]);
	if (pre[x] == low[x]) {
		cnt++; st[top] = 0;
		while (st[top] != x) top--, scc[st[top]] = cnt;
	}
}
 
void tarjan() {
	memset(pre, 0, sizeof(pre)), memset(scc,0,sizeof(scc));dfn = 0;
	rep(i,1,n * 2) if (!pre[nd[i].second]) dfs(nd[i].second);
}
 
bool check(int m) {
	memset(u, 0, sizeof(u)); l = 0;
	rep(i,1,n) 
		nd[i*2-1] = mp(x[i], B + (i << 1)), 
		nd[i*2] = mp(y[i],B + ((i << 1) | 1));
	sort(nd + 1, nd + 2 * n + 1);
	build(1, 1, n * 2);
	rep(i,1,n * 2) {
		int t = lower_bound(nd + 1, nd + n * 2 + 1, mp(nd[i].first - m + 1, 0)) - nd;
		a = t, b = i - 1, c = nd[i].second; if (a <= b) modi(1, 1, n * 2);
		t = lower_bound(nd + 1, nd + n * 2 + 1, mp(nd[i].first + m - 1, int(1e9))) - nd;
		a = i + 1, b = t - 1, c = nd[i].second; if (a <= b) modi(1, 1, n * 2);
	}
	tarjan();
	rep(i,1,2 * n) if (scc[nd[i].second] == scc[nd[i].second ^ 1]) return false;
	return true;
}
 
int main() {
	scanf("%d",&n); rep(i,1,n) scanf("%d%d",&x[i],&y[i]);
	int l = 0, r = 1e9 + 1;
	while (l + 1 < r) {
		int m = (l + r) >> 1;
		if (check(m)) l = m; else r = m;
	}
	printf("%d\n",l);
	return 0;
}

Submission Info

Submission Time
Task F - Flags
User WuHongxun
Language C++14 (GCC 5.4.1)
Score 1200
Code Size 2704 Byte
Status AC
Exec Time 879 ms
Memory 30976 KB

Compile Error

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

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 20 ms 14592 KB
00_example_02.txt AC 20 ms 14592 KB
00_example_03.txt AC 20 ms 14592 KB
01.txt AC 29 ms 16768 KB
02.txt AC 23 ms 14592 KB
03.txt AC 20 ms 14592 KB
04.txt AC 20 ms 14592 KB
05.txt AC 21 ms 14592 KB
06.txt AC 413 ms 24832 KB
07.txt AC 395 ms 24832 KB
08.txt AC 420 ms 24832 KB
09.txt AC 29 ms 16768 KB
10.txt AC 23 ms 14592 KB
11.txt AC 20 ms 14592 KB
12.txt AC 21 ms 14592 KB
13.txt AC 21 ms 14592 KB
14.txt AC 382 ms 24704 KB
15.txt AC 382 ms 24704 KB
16.txt AC 466 ms 24704 KB
17.txt AC 30 ms 16768 KB
18.txt AC 24 ms 14592 KB
19.txt AC 460 ms 24704 KB
20.txt AC 473 ms 24704 KB
21.txt AC 671 ms 26880 KB
22.txt AC 618 ms 26880 KB
23.txt AC 879 ms 30976 KB
24.txt AC 575 ms 30976 KB
25.txt AC 794 ms 30848 KB
26.txt AC 525 ms 24704 KB
27.txt AC 19 ms 14592 KB