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;
vector<int> 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--){
vector<int> res = query(i);
assert(glo == res);
if(glo[0]+glo[1] == 0){
ans = i;
return;
}
if(glo[0]+glo[1] != loli)continue;
L = i;
break;
}
if(L!=-1){
vector<int> res = query(L);
assert(glo == res);
int x = mid-L;
if(glo[0] - cntl)solve(l,L-1,cntl,glo[1]);
if(glo[1] - cntr - x)solve(mid+1,r,glo[0] + x,cntr);
return;
}
///
for(int i=mid+1;i<=r;i++){
vector<int> res = query(i);
assert(glo == res);
if(glo[0]+glo[1] == 0){
ans = i;
return;
}
if(glo[0]+glo[1] != loli)continue;
R = i;
break;
}
if(R == -1)return;
vector<int> res = query(R);
assert(glo == res);
if(glo[1] - cntr)solve(R+1,r,glo[0],cntr);
}
int find_best(int n) {
int p = 0;
for(int i=0;i<min(n,477);i++){
vector<int> res = query(i);
assert(glo == res);
if(glo[0]+glo[1] == 0)return i;
if(glo[0]+glo[1] > loli){
loli = glo[0]+glo[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... |