#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) {
if(a[0]+a[1] < maxi) {
i1 = middle;
}else i1 = middle-1;
}else {
if(a[0]+a[1] < maxi) {
i1 = middle;
}else i1 = middle+1;
}
}
}
auto a = myAsk(i1);
if (a[0] + a[1] == 0) return i1;
last = i1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
11352 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
68 ms |
11352 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |