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;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
typedef pair<int,int> pii;
int loli = 0;
vector<vector<int>>memo(222222,{-1,-1});
vector<int>glo;
auto query(int x){
if(memo[x][0] == -1)memo[x] = ask(x);
glo = memo[x];
return memo[x];
}
int ans = 0;
void solve(int l,int r,int cntl,int cntr){
//cout<<l<<" "<<r<<" "<<cntl<<" "<<cntr<<'\n';
int mid = (l+r)/2;
int L = -1,R = -1;
for(int i=mid;i>=l;i--){
auto res = query(i);
assert(glo == res);
if(res[0]+res[1] == 0){
ans = i;
return;
}
if(res[0]+res[1] != loli)continue;
L = i;
break;
}
if(L!=-1){
auto res = query(L);
assert(glo == res);
int x = mid-L;
if(res[0] - cntl)solve(l,L-1,cntl,res[1]);
if(res[1] - cntr - x)solve(mid+1,r,res[0] + x,cntr);
return;
}
///
for(int i=mid+1;i<=r;i++){
auto res = query(i);
assert(glo == res);
if(res[0]+res[1] == 0){
ans = i;
return;
}
if(res[0]+res[1] != loli)continue;
R = i;
break;
}
if(R == -1)return;
auto res = query(R);
assert(glo == res);
if(res[1] - cntr)solve(R+1,r,res[0],cntr);
}
int find_best(int n) {
int p = 0;
for(int i=0;i<min(n,477);i++){
auto res = query(i);
assert(glo == res);
if(res[0]+res[1] == 0)return i;
if(res[0]+res[1] > loli){
loli = res[0]+res[1];
p = i;
}
if(loli >= 27)break;
}
solve(p,n-1,p,0);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |