제출 #73988

#제출 시각아이디문제언어결과실행 시간메모리
73988renatsj커다란 상품 (IOI17_prize)C++14
90 / 100
106 ms2112 KiB
#include<bits/stdc++.h>
#include "prize.h"
using namespace std;
int i,j,n,m,l,r,c,xl,xr,maz,rez,mas[200005][2];
vector<int> xx;
vector<int> aask(int h)
{
    if (mas[h][0]==-1&&mas[h][1]==-1)
    {
        xx=ask(h);
        mas[h][0]=xx[0];
        mas[h][1]=xx[1];
    }
    else
    {
        xx[0]=mas[h][0];
        xx[1]=mas[h][1];
    }
    return xx;
}
int find_best(int n)
{
    i=0;
    while (i<n-1)
    {
        mas[i][0]=-1;
        mas[i][1]=-1;
        i++;
    }
    l=0;
    r=n-1;
    rez=0;
    maz=0;
    while (true)
    {
        while (l<r)
        {
            c=l+(r-l)/2;
            xx=aask(c);
            xl=xx[0];
            xr=xx[1];
            if (xl+xr==0)
            {
                return c;
            }
            if (xl+xr>maz)
            {
                l=0;
                r=n-1;
                rez=0;
                maz=xl+xr;
            }
            else if (xl+xr<maz)
            {
                r=c;
            }
            else if (xl>rez)
            {
                r=c-1;
            }
            else
            {
                l=c+1;
            }
        }
        if (l<=n-1)
        {
            xx=aask(l);
            xl=xx[0];
            xr=xx[1];
        }
        if (xl+xr==0)
        {
            return l;
        }
        rez++;
        l++;
        if (l<=n-1)
        {
            xx=(aask(l));
            xl=xx[0];
            xr=xx[1];
            if (xl+xr==0)
            {
                return l;
            }
        }
        while (xl+xr<maz&&l<n-1)
        {
            l++;
            rez++;
            xx=(aask(l));
            xl=xx[0];
            xr=xx[1];
            if (xl+xr==0)
            {
                return l;
            }
        }
        if (xl+xr>maz)
        {
            maz=xl+xr;
            l=0;
            r=n-1;
            rez=0;
        }
        r=n-1;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...