This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
using ll = int;
int find_best(int n) {
mt19937_64 mt(random_device{}());
vector<array<ll,2>> mem(n,{-1,-1});
auto qry = [&](ll i){
if (mem[i][0]==-1){
auto a = ask(i);
mem[i] = {a[0],a[1]};
}
return mem[i];
};
/*
ll cnt = 0;
vector<ll> a(n);
iota(a.begin(),a.end(),0);
shuffle(a.begin(),a.end(),mt);*/
ll ans = -1;
function<void(ll,ll)> dfs;
dfs = [&](ll l, ll r){
if (ans != -1) return;
if (l == r){
ans = l;
return;
}
ll m = l+r>>1;
auto o = qry(m);
if (o[0]+o[1]==0) {
ans = m;
return;
}
if (o[0]){
dfs(l,m-1);
}
if(o[1]){
dfs(m+1,r);
}
};
dfs(0,n-1);
return ans;
}
Compilation message (stderr)
prize.cpp: In lambda function:
prize.cpp:28:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | ll m = l+r>>1;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |