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 <iostream>
using namespace std;
vector <int> a;
int maxs;
int cur[512];
int find_prize(int l, int r, int bigl, int bigr) {
int mid=(l+r)/2;
while (mid<=r) {
a=ask(mid);
if (a[0]+a[1]==0) return mid;
if (a[0]+a[1]==maxs) break;
mid++;
}
int ans=-1;
if (mid<=r && a[0]+1<=bigr) {
ans=find_prize(mid+1,r,a[0]+1,bigr);
if (ans!=-1) return ans;
}
mid=(l+r)/2-1;
while (mid>=l) {
a=ask(mid);
if (a[0]+a[1]==0) return mid;
if (a[0]+a[1]==maxs) break;
mid--;
}
if (mid>=l && a[0]>=bigl) {
ans=find_prize(l,mid-1,bigl,a[0]);
if (ans!=-1) return ans;
}
return ans;
}
int find_best(int n) {
for (int i=0;i<500;i++) {
a=ask(i);
if (a[0]+a[1]==0) return i;
maxs=max(maxs,a[0]+a[1]);
cur[i]=a[0]+a[1];
}
int cnt=0;
for (int i=0;i<500;i++) if (cur[i]!=maxs) cnt++;
int ans=find_prize(0,n-1,cnt+1,maxs);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |