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;
vector<int> dp[200000];
vector<int> myAsk(int n) {
if (dp[n][0] == -1) dp[n] = ask(n);
return dp[n];
}
int find_best(int n) {
for (int i = 0; i < n; i++) {
dp[i] = {-1, -1};
}
int maxi = 0;
for (int i = 0; i < min(450, n); i++) {
maxi = max(maxi, myAsk(i)[0] + myAsk(i)[1]);
}
int last = 0;
auto a = myAsk(0);
if (a[0] + a[1] == 0) return 0;
int y = n;
while (y--) {
int i1 = last + 1;
int i2 = n - 1;
if (myAsk(i1)[0] + myAsk(i1)[1] == maxi) {
last = i1;
continue;
}
while (i1 != i2) {
int middle = (i1 + i2) / 2;
auto a = myAsk(middle);
if (a[0] + a[1] == 0) return middle;
if(middle == i1) {
i1 = i2;
}else {
auto b = myAsk(i1);
if(a[0]-b[0] > 0) {
i2 = middle-1;
}else {
i1 = middle;
}
}
}
auto a = myAsk(i1);
if (a[0] + a[1] == 0) return i1;
last = i1;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |