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<bits/stdc++.h>
#include "prize.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int pos;
map<int,pii> dic;
pii query(int p){
if(dic.find(p)!=dic.end()) return dic[p];
vector<int> q=ask(p);
return dic[p]=pii(q[0],q[1]);
}
pii solve(int l,int r,pii tar){
if(pos!=-1) return pii(0,0);
if(l==r){
pii q=query(l);
if(q.first==0 && q.second==0 && pos==-1) pos=l;
return q;
}
int mid=(l+r)>>1;
pii q=query(mid+1);
if(q.first==0 && q.second==0 && pos==-1) pos=mid+1;
if(pos!=-1) return pii(0,0);
if(q.first!=tar.first || q.second!=tar.second) tar=solve(mid+1,r,tar);
if(pos!=-1) return pii(0,0);
return solve(l,mid,tar);
}
int find_best(int n){
pos=-1;
pii q=query(n-1);
if(q.first==0 && q.second==0) return n-1;
solve(0,n-1,q);
return pos;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |