Submission #249778

#TimeUsernameProblemLanguageResultExecution timeMemory
249778stoyan_malininThe Big Prize (IOI17_prize)C++14
20 / 100
110 ms384 KiB
#include "prize.h"
//#include "grader.cpp"

#include <iostream>
#include <vector>

using namespace std;

int getLeft(int i)
{
    vector <int> res = ask(i);
    return res[0];
}

int getRight(int i)
{
    vector <int> res = ask(i);
    return res[1];
}

int getSum(int i)
{
    vector <int> res = ask(i);
    return res[0] + res[1];
}

pair <int, int> get(int i)
{
    vector <int> res = ask(i);
    return {res[0], res[1]};
}

bool check(pair <int, int> base, int newLast)
{
    if(base==get(newLast)) return true;
    return false;
}

int find_best(int n)
{
    int goalSum = 0;
    for(int i = 0;i<min(n, 460);i++)
    {
        int curr = getSum(i);
        goalSum = max(goalSum, curr);

        //if(curr==0) return i;
    }

    int ind = 0;
    while(ind<n)
    {
        //cout << " --- " << ind << " --- " << '\n';

        pair <int, int> base;
        while(ind<n)
        {
            pair <int, int> curr = get(ind);
            base = curr;

            if(curr.first+curr.second==goalSum) break;
            if(curr.first+curr.second==0) return ind;

            ind++;
        }

        int last = ind;
        for(int i = (1LL<<18);i>=1;i/=2)
        {
            if(last+i>=n) continue;
            if(check(base, last+i)==true) last += i;
        }

        ind = last + 1;
    }
}
/*
9
3 3 2 3 2 3 1 3 3
*/

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:76:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...