Submission #597854

#TimeUsernameProblemLanguageResultExecution timeMemory
597854yanndevThe Big Prize (IOI17_prize)C++17
20 / 100
83 ms6264 KiB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;

int totQ = 0;
vector<int> ans[200042];
bool fucked[200042];

vector<int> query(int i) {
    if (ans[i].empty()) {
        totQ++;
        return ans[i] = ask(i);
    }
    return ans[i];
}

int find_best(int n) {
    srand(10);
    vector<int> nxt {};
    for (int i = 0; i < n; i++)
        nxt.push_back(i);
    random_shuffle(nxt.begin(), nxt.end());

    while (!nxt.empty()) {
        int i = nxt.back();
        nxt.pop_back();
        if (fucked[i])
            continue;

        vector<int> a = query(i);
        if (a[0] == 0 && a[1] == 0)
            return i;
        
        int l = i;
        int r = n - 1;
        while (l < r) {
            int m = (l + r + 1) / 2;
            vector<int> b = query(m);
            if (b[0] == a[0] && b[1] == a[1])
                l = m;
            else
                r = m - 1;
        }

		//cout << "poor range " << i << ' ' << l << '\n';
        for (int j = i; j <= l; j++)
            fucked[j] = true;
    }
}

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:19:22: warning: control reaches end of non-void function [-Wreturn-type]
   19 |     vector<int> nxt {};
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...