이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> lcache;
vector<int> rcache;
int n;
pair<int,int> askmap(int i){
//cout<<"askmap "<<i<<endl;
if (i>=n){
return {1e9,1e9};
}
assert(i<n);
if (lcache[i]==-1){
vector<int> res = ask(i);
lcache[i] = res[0];
rcache[i] = res[1];
}
return {lcache[i],rcache[i]};
}
int asksum(int i){
auto p = askmap(i);
return p.first+p.second;
}
int lsum = 0;
int dnc(int s, int e, int numexp, int prefexp, int suffexp){
// numexp expensive things in range s->e
//cout<<s<<' '<<e<<' '<<numexp<<' '<<prefexp<<' '<<suffexp<<endl;
if (e-s+1==numexp){
for (int i = s; i<=e; i++){
if (asksum(i)==0){return i;}
}
return -1;
}
if (numexp==0){
return -1;
}
// there is at least one lollipop
int m = (s+e)/2;
for (int i = m; i>=s; i--){
if (asksum(i)==lsum){
auto m = askmap(i);
int lval = m.first;
int rval = m.second;
int dl = dnc(s,i-1,lval-prefexp, prefexp, rval);
if (dl!=-1){return dl;}
int dr = dnc(i+1,e,rval-suffexp, lval, suffexp);
if (dr!=-1){return dr;}
return -1;
} else if (asksum(i)==0){
return i;
}
}
for (int i = m+1; i<=e; i++){
if (asksum(i)==lsum){
auto m = askmap(i);
int lval = m.first;
int rval = m.second;
//int dl = dnc(s,i-1,lval-prefexp, prefexp, rval);
//if (dl!=-1){return dl;}
int dr = dnc(i+1,e,rval-suffexp, lval, suffexp);
if (dr!=-1){return dr;}
return -1;
} else if (asksum(i)==0){
return i;
}
}
assert(1==0);
}
int find_best(int N) {
n=N;
lcache.resize(n,-1);
rcache.resize(n,-1);
if (n<=1000){
for (int i = 0; i < n; i++) {
if(asksum(i) == 0){
return i;
}
}
assert(1==0);
}
int m = (n-1)/2;
for (int i = m-475; i<m; i++){
int res = asksum(i);
if (res==0){return i;}
lsum = max(res,lsum);
}
return dnc(0,n-1,lsum,0,0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |