Submission #85113

# Submission time Handle Problem Language Result Execution time Memory
85113 2018-11-18T14:15:02 Z nikolapesic2802 popa (BOI18_popa) C++14
0 / 100
45 ms 500 KB
#include <bits/stdc++.h>
#include "popa.h"
using namespace std;

#define ll long long
#define pb push_back
/*bool query(int a,int b,int c,int d)
{
    printf("%i-%i  %i-%i?\n",a,b,c,d);
    int res;
    scanf("%i",&res);
    return res;
}*/
bool levo(int poz)
{
    return query(poz,poz,poz-1,poz);
}
bool desno(int poz)
{
    return query(poz,poz,poz,poz+1);
}
int solve(int _N,int* Left,int* Right)
{
    int n=_N;
    for(int i=0;i<n;i++)
    {
        Left[i]=-1;
        Right[i]=-1;
    }
    vector<int> parent(n);
    fill(parent.begin(),parent.end(),-1);
    for(int i=0;i<n;i++)
    {
        if(i>0&&parent[i]==-1)
        {
            if(levo(i))
            {
                int tr=i-1;
                while(parent[tr]!=-1)
                    tr=parent[tr];
                int l=tr,r=i-1;
                while(l<r)
                {
                    int m=(l+r)>>1;
                    if(query(i,i,m,i))
                    {
                        r=m;
                    }
                    else
                    {
                        l=m+1;
                    }
                }
                parent[i]=parent[l];
                if(parent[i]!=-1)
                    Right[parent[i]]=i;
                Left[i]=l;
                parent[l]=i;
            }
            else
            {
                assert(0);
            }
        }
        if(i<n-1)
        {
            if(desno(i))
            {
                assert(parent[i+1]==-1);
                parent[i+1]=i;
                Right[i]=i+1;
            }
        }
    }
    int cnt=0,poz;
    for(int i=0;i<n;i++)
    {
        if(parent[i]==-1){
            poz=i;
            cnt++;
        }
    }
    assert(cnt==1);
    return poz;
    //assert(0);
    /*printf("Left:\n");
    for(int i=0;i<n;i++)
    {
        printf("%i ",Left[i]);
    }
    printf("\nRight:\n");
    for(int i=0;i<n;i++)
    {
        printf("%i ",Right[i]);
    }*/
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 376 KB not a binary tree
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 500 KB not a binary tree
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 500 KB too many queries
2 Halted 0 ms 0 KB -