Submission #3221446


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;
const int N=40010;
struct Edge{int from,to,next;} e[N<<5];
int h[N<<2],sum=0;
int low[N<<2],pre[N<<2];
int scc[N<<2],dfn,cnt;
int a[2][N],n;
pii Hash[N<<1];
stack<int> stk;
int node[N<<4],tot;

void add_edge(int u,int v)
{
    if(u==v) return;
    e[++sum].to=v;
    e[sum].from=u;
    e[sum].next=h[u];
    h[u]=sum;
}

void Build(int o,int l,int r)
{
    if(l==r)
    {
        node[o]=Hash[l].second;
        return;
    }
    node[o]=++tot;
    int mid=(l+r)/2;
    Build(o<<1,l,mid);
    Build(o<<1|1,mid+1,r);
    add_edge(node[o],node[o<<1]);
    add_edge(node[o],node[o<<1|1]);
}

void link(int o,int l,int r,int nl,int nr,int u)
{
    if(nl>nr) return;
    if(l>=nl&&r<=nr)
    {
        add_edge(u,node[o]);
        return;
    }
    int mid=(l+r)/2;
    if(nl<=mid) link(o<<1,l,mid,nl,nr,u);
    if(nr>mid) link(o<<1|1,mid+1,r,nl,nr,u);
}

void Init()
{
    for(int i=1;i<=n;i++)
    {
        Hash[2*i-1].first=a[0][i];
        Hash[2*i-1].second=i+n;
        Hash[2*i].first=a[1][i];
        Hash[2*i].second=i;
    }
    sort(Hash+1,Hash+1+2*n);
}

void Tarjan(int u)
{
    stk.push(u);
    low[u]=pre[u]=++dfn;
    for(int tmp=h[u];tmp;tmp=e[tmp].next)
        if(!pre[e[tmp].to])
        {
            Tarjan(e[tmp].to);
            low[u]=min(low[u],low[e[tmp].to]);
        }
        else if(!scc[e[tmp].to]) low[u]=min(low[u],pre[e[tmp].to]);
    if(pre[u]==low[u])
    {
        int o;cnt++;
        do{
            o=stk.top();
            stk.pop();
            scc[o]=cnt;
        }while(o!=u);
    }
}

bool check(int x)
{
    sum=dfn=cnt=0;tot=2*n;
    memset(h,0,sizeof(h));
    Build(1,1,2*n);
    for(int i=1;i<=n;i++)
        for(int k=0;k<2;k++)
        {
            int l=lower_bound(Hash+1,Hash+1+2*n,pii(a[k][i]-x+1,0))-Hash;
            int r=upper_bound(Hash+1,Hash+1+2*n,pii(a[k][i]+x-1,2*n+1))-Hash-1;
            int m=lower_bound(Hash+1,Hash+1+2*n,pii(a[k][i],(k^1)*n+i))-Hash;
            link(1,1,2*n,l,m-1,k*n+i);
            link(1,1,2*n,m+1,r,k*n+i);
        }
    while(!stk.empty()) stk.pop();
    memset(pre,0,sizeof(pre));
    memset(low,0,sizeof(low));
    memset(scc,0,sizeof(scc));
    for(int i=1;i<=tot;i++)
        if(!pre[i]) Tarjan(i);
    for(int i=1;i<=n;i++)
        if(scc[i]==scc[i+n]) return 0;
    return 1;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[0][i],&a[1][i]);
    Init();
    int l=0,r=int(1e9),mid;
    while(l<r)
    {
        mid=(l+r)/2;
        if(check(mid)) l=mid+1;
        else r=mid-1;
    }
    printf("%d\n",check(l)?l:l-1);
    return 0;
}

Submission Info

Submission Time
Task F - Flags
User luogu_bot2
Language C++ (GCC 5.4.1)
Score 1200
Code Size 2765 Byte
Status AC
Exec Time 449 ms
Memory 16384 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:113:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:115:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a[0][i],&a[1][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 6 ms 4352 KB
00_example_02.txt AC 5 ms 4352 KB
00_example_03.txt AC 6 ms 4352 KB
01.txt AC 15 ms 4352 KB
02.txt AC 9 ms 4352 KB
03.txt AC 7 ms 4352 KB
04.txt AC 7 ms 4352 KB
05.txt AC 7 ms 4352 KB
06.txt AC 349 ms 12288 KB
07.txt AC 349 ms 12288 KB
08.txt AC 350 ms 12288 KB
09.txt AC 15 ms 4352 KB
10.txt AC 9 ms 4352 KB
11.txt AC 6 ms 4352 KB
12.txt AC 6 ms 4352 KB
13.txt AC 7 ms 4352 KB
14.txt AC 346 ms 12288 KB
15.txt AC 347 ms 12288 KB
16.txt AC 347 ms 12288 KB
17.txt AC 16 ms 4480 KB
18.txt AC 10 ms 4352 KB
19.txt AC 379 ms 12416 KB
20.txt AC 376 ms 12416 KB
21.txt AC 449 ms 14336 KB
22.txt AC 448 ms 14336 KB
23.txt AC 446 ms 16384 KB
24.txt AC 357 ms 16256 KB
25.txt AC 364 ms 16000 KB
26.txt AC 371 ms 12416 KB
27.txt AC 5 ms 4352 KB