#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];
};
auto sm = [&](const array<ll,2> &o){return o[0]+o[1];};
ll cnt = 449;
vector<ll> a(n);
iota(a.begin(),a.end(),0);
shuffle(a.begin(),a.end(),mt);
ll mx = 0;
for(ll i = 0;i<cnt;i++){
mx = max(mx,sm(qry(a[i])));
}
ll ans = -1;
function<void(ll,ll,ll,ll)> dfs;
dfs = [&](ll l, ll r,ll dl, ll dr){
if (ans != -1) return;
if (l == r){
ans = l;
return;
}
array<ll,2> o = {-1,-1};
ll m = l+r>>1;
while(sm(o)!=0&&sm(o)!=mx){
m = r-l>=2?l+1+mt()%(r-l-1):l+mt()%2;
o = qry(m);
}
if (sm(o)==0) {
ans = m;
return;
}
if (o[0]-dl>0){
dfs(l,m-1,dl,o[1]);
}
if(o[1]-dr>0){
dfs(m+1,r,o[0],dr);
}
};
dfs(0,n-1,0,0);
return ans;
}
Compilation message
prize.cpp: In lambda function:
prize.cpp:33:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | ll m = l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
2904 KB |
Output is correct |
3 |
Correct |
4 ms |
2648 KB |
Output is correct |
4 |
Correct |
4 ms |
2648 KB |
Output is correct |
5 |
Correct |
4 ms |
2648 KB |
Output is correct |
6 |
Correct |
5 ms |
2904 KB |
Output is correct |
7 |
Correct |
4 ms |
2648 KB |
Output is correct |
8 |
Correct |
4 ms |
2648 KB |
Output is correct |
9 |
Correct |
3 ms |
2648 KB |
Output is correct |
10 |
Correct |
4 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
2648 KB |
Output is correct |
3 |
Correct |
4 ms |
2648 KB |
Output is correct |
4 |
Correct |
3 ms |
2648 KB |
Output is correct |
5 |
Correct |
4 ms |
2648 KB |
Output is correct |
6 |
Correct |
4 ms |
2904 KB |
Output is correct |
7 |
Correct |
4 ms |
2648 KB |
Output is correct |
8 |
Correct |
4 ms |
2728 KB |
Output is correct |
9 |
Correct |
4 ms |
2648 KB |
Output is correct |
10 |
Correct |
5 ms |
2904 KB |
Output is correct |
11 |
Incorrect |
4 ms |
2648 KB |
answer is not correct |
12 |
Halted |
0 ms |
0 KB |
- |