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;
pair<int,int> memo[200005];
pair<int,int> qry(int x){
if(memo[x].first!=-1)return memo[x];
vector<int> v=ask(x);
return memo[x]=make_pair(v[0],v[1]);
}
int find_best(int n){
for(int i=0;i<n;i++)memo[i]=make_pair(-1,-1);
int k=1;
while(k*(k+1)<n)k++;
k++;
int sz=0;
pair<int,int> p;
for(int i=0;i<k;i++){
p=qry(n/k*i);
sz=max(sz,p.first+p.second);
}
for(int i=0;i<n;i++){
p=qry(i);
if(p.first+p.second==0)return i;
if(p.first+p.second!=sz)continue;
int l=i,r=n-1,mid;
while(l<r){
mid=(l+r+1)/2;
if(qry(mid)==p){
l=mid;
}else{
r=mid-1;
}
}
i=l;
}
return n;
}
/*
8
3 2 3 1 3 3 2 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |