Submission #1062396

#TimeUsernameProblemLanguageResultExecution timeMemory
1062396Sir_Ahmed_ImranThe Big Prize (IOI17_prize)C++17
20 / 100
29 ms5924 KiB
                                    ///~~~LOTA~~~///
#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
#define ll long long
#define ld long double
#define append push_back
#define add insert
#define nl '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define terminator main
#define MAXN 200000
vector<int> v[MAXN];
vector<int> get(int x){
    if(v[x].empty())
        v[x]=ask(x);
    return v[x];
}
int find_best(int n){
    int m,o,p,q;
    vector<int> a;
    for(int i=m=0;i<n;i+=256){
        a=get(i);
        m=max(m,a[0]+a[1]);
    }
    p=0;q=n-1;
    while(p<n && q>=0){
        a=get(p);
        if(!a[0] && !a[1])
            return p;
        o=(p+256)/256;
        o*=256;
        if(a[0]+a[1]==m  && get(o)==a) 
            p=o;
        else if(a[0]+a[1]==m){
            for(int i=128;i>0;i/=2){
                if(p+i<n && get(p+i)==a)
                    p+=i;
            }
        }
        p++;
        a=get(q);
        if(!a[0] && !a[1])
            return q;
        o=(q-1)/256;
        o*=256;
        if(a[0]+a[1]==m  && get(o)==a) 
            q=o;
        else if(a[0]+a[1]==m){
            for(int i=128;i>0;i/=2){
                if(q>=i && get(q-i)==a)
                    q-=i;
            }
        }
        q--;
    }
    return -1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...