#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
const int need = 473;
int find_best(int n) {
int mxcnt = 0;
vector<int> res;
int nonmax = 0;
for (int i = 0; i < min(n, need); ++i) {
res = ask(i);
if (res[0] + res[1] == 0) {
return i;
}
if (res[0] + res[1] > mxcnt) {
mxcnt = res[0] + res[1];
nonmax = i;
} else if (res[0] + res[1] < mxcnt) {
++nonmax;
}
}
int last = need - 1;
while (true) {
int left = last, right = n;
while (right - left > 1) {
int mid = left + (right - left) / 2;
res = ask(mid);
if (res[0] + res[1] == 0) {
return mid;
}
if (res[0] + res[1] < mxcnt) {
right = mid;
} else if (res[0] == nonmax) {
left = mid;
} else {
right = mid;
}
}
assert(right != n);
last = right;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
424 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Incorrect |
47 ms |
600 KB |
Incorrect |
12 |
Halted |
0 ms |
0 KB |
- |