Submission #1120089
Source Code Expand
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
// coordinate compression
struct X {
typedef int T;
vector<T> d;
inline void add(T x) { d.pb(x);}
void init() {
sort(rng(d));
d.erase(unique(rng(d)), d.end());
}
inline int size() { return sz(d);}
inline int operator[](T x) { return upper_bound(rng(d),x)-d.begin()-1;}
};
//
// Segment tree (RMQ type)
vi used, q;
vector<P> ps;
struct seg {
vector<vi> d; int x2;
vi e;
seg(){}
seg(int mx) {
x2 = 1; while (x2 < mx) x2 <<= 1;
d.resize(x2<<1); e.resize(x2<<1);
}
void fil() {
drep(i,x2) {
d[i] = d[i<<1];
d[i].insert(d[i].end(), rng(d[i<<1|1]));
}
}
void add(int i, int x=0){
i += x2;
d[i].pb(x);
}
void get(int a, int b, int x) { return get(a,b,x,1,0,x2);}
void get(int a, int b, int x, int i, int l, int r){
if (a <= l && r <= b) {
q.pb(-sz(ps));
ps.pb(P(i,x));
return;
}
int c = (l+r)>>1;
if (a < c) get(a,b,x,i<<1,l,c);
if (c < b) get(a,b,x,i<<1|1,c,r);
}
};
//
int n;
vi a;
bool f(int x) {
int m = n*2;
X xs;
rep(j,3) {
int di = j-1;
rep(i,m) xs.add(a[i] +di);
rep(i,m) xs.add(a[i]-x+1 +di);
rep(i,m) xs.add(a[i]+x +di);
}
xs.init();
vi vs;
{
seg d(sz(xs)+3);
rep(i,m) {
d.add(xs[a[i]],i^1);
}
d.fil();
used = vi(m);
q = vi();
ps = vp(1);
rep(i,m) if (!used[i]) {
q.pb(i);
while (sz(q)) {
int v = q.back(); q.pop_back();
// cout<<v<<" : "<<q<<endl;
if (v >= m) {
vs.pb(v-m);
continue;
}
if (v < 0) {
v = -v;
int di = ps[v].fi, x = ps[v].se;
int& ei = d.e[di];
bool ok = true;
while (ei < sz(d.d[di])) {
if (used[d.d[di][ei]]) ++ei;
else if (d.d[di][ei] == (x^1)) {
if (ei == sz(d.d[di])-1) {
ok = false;
break;
}
++ei; d.d[di].pb(x^1);
} else break;
}
if (!ok) continue;
if (ei == sz(d.d[di])) continue;
q.pb(-v);
q.pb(d.d[di][ei++]);
continue;
}
if (used[v]) continue;
used[v] = 1;
q.pb(m+v);
d.get(xs[a[v]-x+1],xs[a[v]+x],v);
}
// cout<<vs<<endl;
}
}
reverse(rng(vs));
{
seg d(sz(xs)+3);
rep(i,m) {
d.add(xs[a[i]],i);
}
d.fil();
used = vi(m);
q = vi();
ps = vp(1);
int ui = 1;
for (int i : vs) if (!used[i]) {
q.pb(i);
while (sz(q)) {
int v = q.back(); q.pop_back();
if (v < 0) {
v = -v;
int di = ps[v].fi, x = ps[v].se;
int& ei = d.e[di];
bool ok = true;
while (ei < sz(d.d[di])) {
if (used[d.d[di][ei]]) ++ei;
else if (d.d[di][ei] == (x^1)) {
if (ei == sz(d.d[di])-1) {
ok = false;
break;
}
++ei; d.d[di].pb(x^1);
} else break;
}
if (!ok) continue;
if (ei == sz(d.d[di])) continue;
q.pb(-v);
q.pb(d.d[di][ei++]);
continue;
}
if (used[v]) continue;
used[v] = ui;
d.get(xs[a[v^1]-x+1],xs[a[v^1]+x],v);
}
++ui;
}
// cout<<used<<endl;
}
rep(i,m) if (used[i] == used[i^1]) return false;
return true;
}
int main() {
scanf("%d",&n);
a = vi(n*2);
rep(i,n*2) scanf("%d",&a[i]);
// cout<<f(3)<<endl; return 0;
int l = 0, r = INF;
while (l+1<r) {
int c = (l+r)>>1;
if (f(c)) l = c; else r = c;
}
cout<<l<<endl;
return 0;
}
Submission Info
Submission Time
2017-02-19 01:19:46+0900
Task
F - Flags
User
snuke
Language
C++14 (GCC 5.4.1)
Score
1200
Code Size
5999 Byte
Status
AC
Exec Time
2329 ms
Memory
29024 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:225:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:227:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
rep(i,n*2) scanf("%d",&a[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
4 ms
256 KB
00_example_02.txt
AC
1 ms
256 KB
00_example_03.txt
AC
4 ms
256 KB
01.txt
AC
65 ms
1188 KB
02.txt
AC
27 ms
700 KB
03.txt
AC
10 ms
384 KB
04.txt
AC
11 ms
384 KB
05.txt
AC
12 ms
384 KB
06.txt
AC
2143 ms
27332 KB
07.txt
AC
2268 ms
27396 KB
08.txt
AC
2252 ms
27388 KB
09.txt
AC
67 ms
1188 KB
10.txt
AC
28 ms
700 KB
11.txt
AC
10 ms
512 KB
12.txt
AC
11 ms
384 KB
13.txt
AC
13 ms
384 KB
14.txt
AC
2329 ms
27612 KB
15.txt
AC
2276 ms
27548 KB
16.txt
AC
2214 ms
29024 KB
17.txt
AC
65 ms
1192 KB
18.txt
AC
27 ms
700 KB
19.txt
AC
2124 ms
27784 KB
20.txt
AC
2120 ms
27780 KB
21.txt
AC
1210 ms
13680 KB
22.txt
AC
1201 ms
14612 KB
23.txt
AC
543 ms
7144 KB
24.txt
AC
919 ms
14624 KB
25.txt
AC
388 ms
6820 KB
26.txt
AC
1302 ms
19284 KB
27.txt
AC
1 ms
256 KB