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<bits/stdc++.h>
#include "prize.h"
using namespace std;
const int MAX_VAL=200*1000+5;
int nbVal,nbPasMax,rep,nbTest;
vector<pair<int,int>> interCour,interNouv;
vector<int> memo[MAX_VAL];
void calc(int deb,int fin,int nbGau,int nbDro) {
if (fin<deb or nbGau+nbDro==nbPasMax) {
return;
}
int mid=(deb+fin)/2;
vector<int> ans;
if (memo[mid].empty()) {
ans=ask(mid);
memo[mid]=ans;
}
else {
ans=memo[mid];
}
if (ans[0]+ans[1]<nbPasMax) {
if (ans[0]+ans[1]==0) {
rep=mid;
}
calc(deb,mid-1,nbGau,ans[1]+1);
calc(mid+1,fin,ans[0]+1,nbDro);
}
else {
calc(deb,mid-1,nbGau,ans[1]);
calc(mid+1,fin,ans[0],nbDro);
}
}
int find_best(int n) {
nbVal=n;
nbTest=500;
int deb,fin,mid;
vector<int> ans;
interCour.push_back({0,nbVal-1});
while (!interCour.empty() and nbTest>0) {
interNouv.clear();
for (auto i:interCour) {
deb=i.first;
fin=i.second;
mid=(deb+fin)/2;
if (nbTest>0) {
nbTest--;
ans=ask(mid);
memo[mid]=ans;
nbPasMax=max(nbPasMax,ans[0]+ans[1]);
if (mid-1>=deb) {
interNouv.push_back({deb,mid-1});
}
if (mid+1<=fin) {
interNouv.push_back({mid+1,fin});
}
}
}
interCour=interNouv;
}
calc(0,nbVal-1,0,0);
return rep;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |