Submission #112176

#TimeUsernameProblemLanguageResultExecution timeMemory
112176someone_aaThe Big Prize (IOI17_prize)C++17
0 / 100
55 ms592 KiB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;
const int maxn = 200100;

bool visited[maxn];

int find_best(int n) {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

    srand(time(NULL));

    if(n <= 10000) {
        for(int i=1;i<=n;i++) {
            vector<int>v = ask(i);
            if(v[0] == v[1]) return i;
        }
    }

    int fst = 0, lst = INT_MAX;
    for(int i=1;i<=4500;i++) {
        int x = uniform_int_distribution<int>(0, n)(rng);

        while(visited[x]) x = uniform_int_distribution<int>(0, n)(rng);

        visited[x] = true;

        vector<int>v = ask(x);

        if(v[0] == v[1]) return x;

        // looking for the last {0, 1}
        // looking for the first {1, 0}
        if(v[0] == 0) fst = max(fst, x);
        else if(v[1] == 0 && x >= fst) lst = min(lst, x);
    }

    for(int i=fst;i<=lst;i++) {
        vector<int>v = ask(i);
        if(v[0] == v[1]) return i;
    }

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...