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;
map<int,pair<int,int>>mp;
int cnt=0;
pair<int,int>pors(int u){
if(mp.count(u)==0){
cnt++;
if(cnt>=10000){
exit(23);
}
vector<int>hey=ask(u);
mp[u]=make_pair(hey[0],hey[1]);
}
return mp[u];
}
int find_best(int n) {
int cnta=0;
for(int i=0;i<n;){
//cout<<i<<endl;
pair<int,int>av=pors(i);
if(av.first+av.second==0){
return i;
}
cnta++;
pair<int,int>fake;
int low=i,high=n,mid;
for(auto x:mp){
mid=x.first;
fake=pors(mid);
if(fake.first+fake.second!=av.first+av.second){
high=mid;
}else{
if(fake.first-av.first==0){
low=mid;
}else{
high=mid;
}
}
}
low=max(low,i);
high=n;
while(high-low>1){
mid=(high+low)>>1;
fake=pors(mid);
//cout<<i<<" "<<mid<<" "<<av.first<<" "<<av.second<<" "<<fake.first<<" "<<fake.second<<endl;
if(fake.first+fake.second!=av.first+av.second){
high=mid;
}else{
if(fake.first-av.first==0){
low=mid;
}else{
high=mid;
}
}
}
i=low+1;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |