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;
int l[200005],r[200005],x[200005],answer=-1;
void solve(int L,int R){
if(answer!=-1) return;
if(L+1==R){
return;
}
int m=(L+R)>>1;
vector<int>res=ask(m);
l[m]=res[0];
r[m]=res[1];
if(l[m]+r[m]==0){
answer=m;
return;
}
if(l[m]!=l[L] || r[m]!=r[L]){
solve(L,m);
}
if(answer!=-1) return;
if(l[m]!=l[R] || r[m]!=r[R]){
solve(m,R);
}
}
int find_best(int n){
// for(int i = 0; i < n; i++){
// std::vector<int> res = ask(i);
// if(res[0] + res[1] == 0)
// return i;
// }
for(int i=0;i<n;i++){
l[i]=r[i]=-1;
}
int m=(n-1)/2;
vector<int>res=ask(0);
l[0]=res[0];
r[0]=res[1];
if(l[0]+r[0]==0) return 0;
res=ask(n-1);
l[n-1]=res[0];
r[n-1]=res[1];
if(l[n-1]+r[n-1]==0) return n-1;
solve(0,n-1);
return answer;
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:35:6: warning: unused variable 'm' [-Wunused-variable]
35 | int m=(n-1)/2;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |