Submission #1118887
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;
int n, cnt, nodes;
int x[10000], y[10000];
PII p[20000];
vector<int> g[320000], rev[320000];
int ord[320000], ordc;
int cmp[320000];
bool used[320000];
void dfs1(int v) {
used[v] = true;
for (int to : g[v]) {
if (!used[to]) {
dfs1(to);
}
}
ord[ordc++] = v;
}
int col;
void dfs2(int v) {
cmp[v] = col;
for (int to : rev[v]) {
if (cmp[to] == -1) {
dfs2(to);
}
}
}
int main() {
//freopen("input.txt", "r", stdin);
scanf("%d", &n);
forn(i, n) scanf("%d%d", x + i, y + i);
cnt = 2 * n;
forn(i, n) {
p[i] = mp(x[i], 2 * i);
p[n + i] = mp(y[i], 2 * i + 1);
}
sort(p, p + cnt);
// forn(i, cnt) cerr << p[i].first << ' ' << p[i].second << endl;
// cerr << "---\n";
nodes = 16 * cnt;
forn(i, cnt) {
for (int j = 0; i + (2 << j) <= cnt; ++j) {
if (j == 0) {
g[cnt + i].pb(p[i].second ^ 1);
g[cnt + i].pb(p[i + 1].second ^ 1);
} else {
g[(j + 1) * cnt + i].pb(j * cnt + i);
g[(j + 1) * cnt + i].pb(j * cnt + i + (1 << j));
}
}
}
// forn(i, nodes) for (int to : g[i]) {
// cerr << i << ' ' << to << endl;
// }
// cerr << "---" << endl;
int lo = 0, hi = int(1e9);
while (lo < hi) {
int mid = (lo + hi + 1) >> 1;
forn(i, cnt) {
g[i].clear();
}
int j = 0;
forn(i, cnt - 1) {
while (j < cnt - 1 && p[j + 1].first - p[i].first < mid) {
++j;
}
if (j > i) {
int from = i + 1;
int to = j;
int cnt = j - i;
int sz = 0;
while ((2 << sz) < cnt) {
++sz;
}
if (sz == 0) {
g[p[i].second].pb(p[from].second ^ 1);
if (cnt == 2) {
g[p[i].second].pb(p[from + 1].second ^ 1);
}
} else {
g[p[i].second].pb(sz * ::cnt + from);
g[p[i].second].pb(sz * ::cnt + to + 1 - (1 << sz));
}
}
}
j = cnt - 1;
for (int i = cnt - 1; i >= 0; --i) {
while (j > 0 && p[i].first - p[j - 1].first < mid) {
--j;
}
if (j < i) {
int from = j;
int to = i - 1;
int cnt = i - j;
int sz = 0;
while ((2 << sz) < cnt) {
++sz;
}
if (sz == 0) {
g[p[i].second].pb(p[from].second ^ 1);
if (cnt == 2) {
g[p[i].second].pb(p[from + 1].second ^ 1);
}
} else {
g[p[i].second].pb(sz * ::cnt + from);
g[p[i].second].pb(sz * ::cnt + to + 1 - (1 << sz));
}
}
}
forn(i, nodes) {
rev[i].clear();
}
forn(i, nodes) for (int to : g[i]) {
// if (mid == 3) cerr << i << ' ' << to << endl;
rev[to].pb(i);
}
forn(i, nodes) used[i] = false;
ordc = 0;
forn(i, nodes) if (!used[i]) {
dfs1(i);
}
forn(i, nodes) cmp[i] = -1;
col = 0;
forn(i, nodes) {
int v = ord[nodes - 1 - i];
if (cmp[v] == -1) {
dfs2(v);
++col;
}
}
bool ok = true;
forn(i, n) if (cmp[2 * i] == cmp[2 * i + 1]) {
ok = false;
break;
}
if (ok) {
lo = mid;
} else {
hi = mid - 1;
}
}
cout << lo << endl;
return 0;
}
Submission Info
Submission Time
2017-02-18 22:33:40+0900
Task
F - Flags
User
HellKitsune
Language
C++14 (GCC 5.4.1)
Score
1200
Code Size
4240 Byte
Status
AC
Exec Time
1887 ms
Memory
49920 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:41:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:42:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
forn(i, n) scanf("%d%d", x + i, y + i);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
1200 / 1200
Status
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
6 ms
16000 KB
00_example_02.txt
AC
6 ms
16000 KB
00_example_03.txt
AC
7 ms
16128 KB
01.txt
AC
21 ms
17024 KB
02.txt
AC
11 ms
16384 KB
03.txt
AC
8 ms
16128 KB
04.txt
AC
8 ms
16128 KB
05.txt
AC
8 ms
16128 KB
06.txt
AC
1262 ms
48128 KB
07.txt
AC
1274 ms
49920 KB
08.txt
AC
1283 ms
48128 KB
09.txt
AC
20 ms
17024 KB
10.txt
AC
11 ms
16384 KB
11.txt
AC
7 ms
16128 KB
12.txt
AC
8 ms
16128 KB
13.txt
AC
8 ms
16128 KB
14.txt
AC
1229 ms
48256 KB
15.txt
AC
1266 ms
48256 KB
16.txt
AC
1303 ms
48256 KB
17.txt
AC
21 ms
16896 KB
18.txt
AC
11 ms
16384 KB
19.txt
AC
1263 ms
47104 KB
20.txt
AC
1257 ms
47104 KB
21.txt
AC
1878 ms
47232 KB
22.txt
AC
1801 ms
47104 KB
23.txt
AC
1887 ms
44544 KB
24.txt
AC
1320 ms
48384 KB
25.txt
AC
1409 ms
44672 KB
26.txt
AC
1231 ms
46848 KB
27.txt
AC
6 ms
16000 KB