답안 #85120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
85120 2018-11-18T14:29:10 Z nikolapesic2802 popa (BOI18_popa) C++14
61 / 100
129 ms 644 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))
            {*/
            vector<int> mog;
            int tr=i-1;
            mog.pb(tr);
            while(parent[tr]!=-1){
                tr=parent[tr];
                mog.pb(tr);
            }
            reverse(mog.begin(),mog.end());
            int l=0,r=mog.size()-1;
            while(l<r)
            {
                int m=(l+r)>>1;
                if(query(i,i,mog[m],i))
                {
                    r=m;
                }
                else
                {
                    l=m+1;
                }
            }
            l=mog[l];
            //printf("Postavljam %i izmedju %i i %i\n",i,l,parent[l]);
            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);
    /*queue<int> q;
    q.push(poz);
    vector<int> visited(n);
    while(!q.empty())
    {
        int tr=q.front();
        q.pop();
        if(tr==-1)
            continue;
        visited[tr]=1;
        q.push(Left[tr]);
        q.push(Right[tr]);
    }
    for(int i=0;i<n;i++)
        assert(visited[i]);*/
    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]);
    }*/
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 248 KB Output is correct
2 Correct 12 ms 324 KB Output is correct
3 Correct 17 ms 400 KB Output is correct
4 Correct 11 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 644 KB Output is correct
2 Correct 129 ms 644 KB Output is correct
3 Correct 82 ms 644 KB Output is correct
4 Correct 92 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 644 KB too many queries
2 Halted 0 ms 0 KB -