Submission #1119218
Source Code Expand
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MAXN = 12000;
int en[MAXN * 20];
int was[MAXN * 20];
vector<int> eds[MAXN * 20];
int n;
vector<pair<ll, int> > vv;
ll x[MAXN];
ll y[MAXN];
void st(int v) {
en[v] = 1;
for (int u: eds[v]) {
if (!en[u])
st(u);
}
}
void dfs1(int v) {
was[v] = 1;
for (int u: eds[v]) {
if (!was[u])
dfs1(u);
}
if (v < 2 * n) {
if (!en[v] && !en[v ^ 1]) {
st(v);
}
}
}
void add(int v, int tl, int tr, int l, int r, int x) {
if (r <= tl || tr <= l)
return;
if (l <= tl && tr <= r) {
eds[x].push_back(v + 2 * n);
eds[v + 2 * n + 4 * vv.size()].push_back(x ^ 1);
return;
}
int m = (tl + tr) >> 1;
add(v * 2 + 1, tl, m, l, r, x);
add(v * 2 + 2, m, tr, l, r, x);
}
void build(int v, int tl, int tr) {
if (tl + 1 == tr) {
eds[v + 2 * n].push_back(vv[tl].second);
eds[vv[tl].second ^ 1].push_back(v + 2 * n + 4 * vv.size());
return;
}
int m = (tl + tr) >> 1;
eds[v + 2 * n].push_back(2 * v + 1 + 2 * n);
eds[v + 2 * n].push_back(2 * v + 2 + 2 * n);
eds[2 * v + 1 + 2 * n + 4 * vv.size()].push_back(v + 2 * n + 4 * vv.size());
eds[2 * v + 2 + 2 * n + 4 * vv.size()].push_back(v + 2 * n + 4 * vv.size());
build(v * 2 + 1, tl, m);
build(v * 2 + 2, m, tr);
}
int check(ll d) {
for (int i = 0; i < 2 * n + 8 * vv.size(); ++i)
eds[i].clear();
build(0, 0, vv.size());
for (int i = 0; i < n; ++i) {
int l = lower_bound(vv.begin(), vv.end(), make_pair(x[i] - d + 1, 0)) - vv.begin();
int r = lower_bound(vv.begin(), vv.end(), make_pair(x[i], 2 * i + 1)) - vv.begin();
if (l < r)
add(0, 0, vv.size(), l, r, 2 * i);
l = lower_bound(vv.begin(), vv.end(), make_pair(x[i], 2 * i + 2)) - vv.begin();
r = lower_bound(vv.begin(), vv.end(), make_pair(x[i] + d, 0)) - vv.begin();
if (l < r)
add(0, 0, vv.size(), l, r, 2 * i);
l = lower_bound(vv.begin(), vv.end(), make_pair(y[i] - d + 1, 0)) - vv.begin();
r = lower_bound(vv.begin(), vv.end(), make_pair(y[i], 2 * i)) - vv.begin();
if (l < r)
add(0, 0, vv.size(), l, r, 2 * i + 1);
l = lower_bound(vv.begin(), vv.end(), make_pair(y[i], 2 * i + 1)) - vv.begin();
r = lower_bound(vv.begin(), vv.end(), make_pair(y[i] + d, 0)) - vv.begin();
if (l < r)
add(0, 0, vv.size(), l, r, 2 * i + 1);
}
for (int i = 0; i < 2 * n + 8 * vv.size(); ++i)
en[i] = 0, was[i] = 0;
for (int i = 0; i < 2 * n; ++i) {
if (!was[i])
dfs1(i);
}
for (int i = 0; i < n; ++i) {
if (en[2 * i] && en[2 * i + 1])
return 0;
}
return 1;
}
ll solve() {
vv.clear();
for (int i = 0; i < n; ++i)
vv.push_back(make_pair(x[i], 2 * i + 1));
for (int i = 0; i < n; ++i)
vv.push_back(make_pair(y[i], 2 * i));
sort(vv.begin(), vv.end());
ll l = 0;
ll r = 1e9 + 100;
while (r - l > 1) {
ll mid = (l + r) >> 1;
if (check(mid))
l = mid;
else
r = mid;
}
return l;
}
ll x2[MAXN];
ll y2[MAXN];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%lld%lld", x + i, y + i);
ll ans = solve();
for (int i = 0; i < 3; ++i) {
vector<int> prm;
for (int i = 0; i < n; ++i)
prm.push_back(i);
random_shuffle(prm.begin(), prm.end());
for (int i = 0; i < n; ++i)
x2[prm[i]] = x[i], y2[prm[i]] = y[i];
for (int i = 0; i < n; ++i)
x[i] = x2[i], y[i] = y2[i];
ans = max(ans, solve());
}
cout << ans << "\n";
return 0;
}
Submission Info
Submission Time
2017-02-18 22:42:18+0900
Task
F - Flags
User
LHiC
Language
C++14 (GCC 5.4.1)
Score
1200
Code Size
3767 Byte
Status
AC
Exec Time
4981 ms
Memory
28048 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:140:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:142:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", 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
3 ms
6016 KB
00_example_02.txt
AC
3 ms
6016 KB
00_example_03.txt
AC
5 ms
6016 KB
01.txt
AC
76 ms
6656 KB
02.txt
AC
27 ms
6272 KB
03.txt
AC
9 ms
6144 KB
04.txt
AC
11 ms
6144 KB
05.txt
AC
12 ms
6144 KB
06.txt
AC
3250 ms
26556 KB
07.txt
AC
3432 ms
24184 KB
08.txt
AC
3315 ms
24312 KB
09.txt
AC
74 ms
6656 KB
10.txt
AC
27 ms
6272 KB
11.txt
AC
9 ms
6144 KB
12.txt
AC
11 ms
6144 KB
13.txt
AC
12 ms
6144 KB
14.txt
AC
3322 ms
21880 KB
15.txt
AC
3271 ms
21880 KB
16.txt
AC
3069 ms
24044 KB
17.txt
AC
85 ms
6656 KB
18.txt
AC
32 ms
6272 KB
19.txt
AC
3762 ms
23800 KB
20.txt
AC
3602 ms
26572 KB
21.txt
AC
4981 ms
24824 KB
22.txt
AC
4759 ms
24696 KB
23.txt
AC
4800 ms
26360 KB
24.txt
AC
4324 ms
28048 KB
25.txt
AC
4512 ms
25848 KB
26.txt
AC
3578 ms
27352 KB
27.txt
AC
3 ms
6016 KB