Submission #1476252
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost {ios_base::sync_with_stdio(false);}
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
typedef vector <int> vi;
const int mod = 1e9+7;
const int inf = 1e9+10;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
const int W = 1e9;
#define maxn 20100
PII t[maxn];
int skladowa[maxn], x[maxn], n, m, a, b, c;
bool odw[maxn];
inline bool odl(int p, int q) {
return abs(p - q);
}
set <PII> q;
vector <int> top;
int Key;
inline void topdfs(int u) {
odw[u] = 1;
while (1)
{
set <PII> :: iterator it = q.lower_bound(mp(x[u] - Key + 1, -inf));
while (it != q.end() && (it->e2 == u || abs(((*it).e2 - u) == n)))++it;
if (it == q.end()) break;
if (abs(x[u] - x[it -> e2]) >= Key) break;
PII tmp = *it;
q.erase(it);
//cout << "Znalazlem krawedz: " << u << ' ' << tmp.e2 << endl;
if (tmp.e2 > n && !odw[tmp.e2 - n]) topdfs(tmp.e2 - n);
else if (tmp.e2 <= n && !odw[tmp.e2 + n]) topdfs(tmp.e2 + n);
}
top.pb(u);
}
inline void ccdfs(int u, int skl) {
odw[u] = 1;
skladowa[u] = skl;
int para = (u <= n)?u+n:u-n;
while (1)
{
set <PII> :: iterator it = q.lower_bound(mp(x[para] - Key + 1, -inf));
while (it != q.end() && (it->e2 == u || it->e2 == para)) ++it;
if (it == q.end()) break;
if (abs(x[para] - x[it -> e2]) >= Key) break;
PII tmp = *it;
q.erase(it);
//cout << "Znalazlem na odwrot: " << para << ' ' << tmp.e2 << endl;
if (!odw[tmp.e2]) ccdfs(tmp.e2, skl);
}
}
inline bool check(int k)
{
Key = k;
int N = 2 * n;
FOR(i, 1, N) odw[i] = 0;
q.clear();
FOR(i, 1, n)
{
q.insert(mp(t[i].e1, i));
q.insert(mp(t[i].e2, i + n));
}
top.clear();
int SKL = 0;
FOR(i, 1, N)
if (!odw[i]) topdfs(i);
assert((int)top.size() == N);
FOR(i, 1, N) skladowa[i] = 0, odw[i] = 0;
q.clear();
FOR(i, 1, n)
{
q.insert(mp(t[i].e1, i));
q.insert(mp(t[i].e2, i + n));
}
for (int i=(int)top.size()-1; i>=0; --i)
if (!odw[top[i]])
{
++SKL;
ccdfs(top[i], SKL);
}
FOR(i, 1, n)
if (skladowa[i] == skladowa[i + n]) return 0;
return 1;
}
int main()
{
boost;
cin >> n;
FOR(i, 1, n)
{
cin >> t[i].e1 >> t[i].e2;
x[i + n] = t[i].e2;
x[i] = t[i].e1;
}
int fx = 0, fy = inf;
while (fx < fy)
{
int sr = (fx + fy)/2+1;
if (!check(sr)) fy = --sr;
else fx = sr;
}
cout << fx;
}
Submission Info
Submission Time |
|
Task |
F - Flags |
User |
Miyukine |
Language |
C++14 (GCC 5.4.1) |
Score |
1200 |
Code Size |
2875 Byte |
Status |
AC |
Exec Time |
533 ms |
Memory |
2688 KB |
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 |
1 ms |
256 KB |
00_example_02.txt |
AC |
1 ms |
256 KB |
00_example_03.txt |
AC |
1 ms |
256 KB |
01.txt |
AC |
12 ms |
384 KB |
02.txt |
AC |
5 ms |
256 KB |
03.txt |
AC |
2 ms |
256 KB |
04.txt |
AC |
3 ms |
256 KB |
05.txt |
AC |
3 ms |
256 KB |
06.txt |
AC |
474 ms |
2512 KB |
07.txt |
AC |
474 ms |
2504 KB |
08.txt |
AC |
475 ms |
2508 KB |
09.txt |
AC |
14 ms |
384 KB |
10.txt |
AC |
6 ms |
256 KB |
11.txt |
AC |
2 ms |
256 KB |
12.txt |
AC |
3 ms |
256 KB |
13.txt |
AC |
3 ms |
256 KB |
14.txt |
AC |
531 ms |
2484 KB |
15.txt |
AC |
533 ms |
2488 KB |
16.txt |
AC |
531 ms |
2484 KB |
17.txt |
AC |
12 ms |
384 KB |
18.txt |
AC |
5 ms |
256 KB |
19.txt |
AC |
464 ms |
2520 KB |
20.txt |
AC |
465 ms |
2520 KB |
21.txt |
AC |
397 ms |
2560 KB |
22.txt |
AC |
397 ms |
2560 KB |
23.txt |
AC |
315 ms |
2688 KB |
24.txt |
AC |
220 ms |
2560 KB |
25.txt |
AC |
208 ms |
2688 KB |
26.txt |
AC |
410 ms |
2520 KB |
27.txt |
AC |
1 ms |
256 KB |