#include "prize.h"
#include <cassert>
// #include <iostream>
#include <vector>
using namespace std;
int find_best(int n) {
int high = n; // not possible
int low = 0; // possible
while (high - low > 1) {
int mid = low + (high - low) / 2;
vector<int> res = ask(mid);
int left = res.at(0);
int right = res.at(1);
assert(left + right <= 1);
if (left + right == 0) {
high = mid + 1; // not possible, because 'current' is the answer
low = mid; // possible
} else if (left == 1) {
high = mid; // not possible, because answer is to the left
} else if (right == 1) {
low = mid + 1; // possible, because answer is to the right
}
}
return low;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
424 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
428 KB |
Output is correct |
7 |
Correct |
0 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 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |