#include "prize.h"
#include<bits/stdc++.h>
using namespace std;
int find_best(int n) {
int mx = 0, lim = 500;
for (int i = 0; i < min(n, lim); i ++) {
vector<int> a = ask(i);
mx = max(mx, a[0] + a[1]);
if (a[0] + a[1] == 0) return i;
}
for (int i = 0; i < n; i ++) {
vector<int> a = ask(i);
if (a[0] + a[1] == mx) {
vector<int> c = ask(min(n - 1, i + 220));
if (a[1] == c[1]) {
i = min(n - 1, i + 220);
continue;
}
int l = 0, r = 220;
while (l < r) {
int mid = (l + r) / 2;
if (i + mid >= n) r = mid;
else {
vector<int> b = ask(i + mid);
if (a[1] == b[1]) l = mid + 1;
else r = mid;
}
}
i = l - 1;
}
else if (a[0] + a[1] == 0) return i;
}
}
Compilation message
prize.cpp: In function 'int find_best(int)':
prize.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
35 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
344 KB |
Output is correct |
3 |
Correct |
12 ms |
344 KB |
Output is correct |
4 |
Correct |
23 ms |
344 KB |
Output is correct |
5 |
Correct |
11 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
10 ms |
344 KB |
Output is correct |
8 |
Correct |
10 ms |
344 KB |
Output is correct |
9 |
Correct |
10 ms |
344 KB |
Output is correct |
10 |
Correct |
23 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
596 KB |
Output is correct |
2 |
Correct |
11 ms |
344 KB |
Output is correct |
3 |
Correct |
13 ms |
344 KB |
Output is correct |
4 |
Correct |
18 ms |
344 KB |
Output is correct |
5 |
Correct |
9 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
10 ms |
344 KB |
Output is correct |
8 |
Correct |
14 ms |
344 KB |
Output is correct |
9 |
Correct |
10 ms |
344 KB |
Output is correct |
10 |
Correct |
14 ms |
344 KB |
Output is correct |
11 |
Incorrect |
57 ms |
344 KB |
Incorrect |
12 |
Halted |
0 ms |
0 KB |
- |