#include <bits/stdc++.h>
#include "prize.h"
using namespace std;
int find_best(int n) {
//binary search the first element each time
map<int, int> hi;
hi[n-1] = 0;
int last = 0;
auto a = ask(0);
if (a[0] + a[1] == 0) return 0;
for (auto k: hi) {
if (k.first > a[0] + a[1])hi[k.first]++;
}
while (true) {
int i1 = last;
int i2 = n - 1;
while (i1 != i2) {
int middle = (i1 + i2) / 2;
auto a = ask(middle);
if (a[0] + a[1] == 0) return middle;
if (a[0] - hi[a[0] + a[1]] == 0) {
i1 = middle+1;
} else {
i2 = middle - 1;
}
}
auto a = ask(i1);
if (a[0] + a[1] == 0) return i1;
last = i1;
for (auto k: hi) {
if (k.first > a[0] + a[1])hi[k.first]++;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Incorrect |
66 ms |
344 KB |
Incorrect |
12 |
Halted |
0 ms |
0 KB |
- |