#include "prize.h"
#include <bits/stdc++.h>
#define ar array
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;
const int N = 10;
int find_best(int n) {
map<int, vector<int>> mp;
auto _ask = [&](int x) {
if (mp.count(x)) return mp[x];
auto res = ask(x);
return mp[x] = res;
};
int mx = 0;
for (int i = 0; i < min(n, N); i++) {
auto res = _ask(i);
mx = max(mx, res[0] + res[1]);
if (res[0] + res[1] == 0) return i;
}
int ANS = -1;
auto solve = [&](auto&& s, vector<int> ask, int ml, int mr) -> void {
if (ml > mr || ask.empty()) return;
int want = (ml + mr) / 2;
int tl = 0, tr = sz(ask) - 1, ans = -1;
/*
cerr << "CUR ML MR WANT " << ml << " " << mr << " " << want << '\n';
for (int x : ask) cerr << x << " ";
cerr << '\n';
*/
while (tl <= tr) {
int mid = (tl + tr) / 2;
auto res = _ask(ask[mid]);
//cerr << "ASK " << ask[mid] << " " << res[0] << " " << res[1] << endl;
if (res[0] + res[1] == 0) {
ANS = ask[mid]; return;
}
if (res[0] + res[1] < mx) {
ask.erase(ask.begin() + mid);
tr--; continue;
}
else {
if (res[0] >= want) ans = mid, tr = mid - 1;
else tl = mid + 1;
}
}
/*
cerr << "DONE " << ans << endl;
for (int x : ask) cerr << x << " ";
cerr << '\n';
*/
if (!~ans) return;
auto res = _ask(ask[ans]);
if (res[0] + res[1] == 0) {
ANS = ask[ans]; return;
}
if (ans - 2 >= 0 && !~ANS) {
s(s, vector<int>(ask.begin(), ask.begin() + ans - 1), ml, want - 1);
}
if (ans + 1 < sz(ask) && !~ANS) {
s(s, vector<int>(ask.begin() + ans + 1, ask.end()), want + 1, mr);
}
};
vector<int> idx(n);
iota(all(idx), 0);
solve(solve, idx, 1, mx);
return ANS;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1960 KB |
Output is correct |
3 |
Correct |
1 ms |
1880 KB |
Output is correct |
4 |
Correct |
1 ms |
1880 KB |
Output is correct |
5 |
Correct |
1 ms |
1880 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
1880 KB |
Output is correct |
8 |
Correct |
1 ms |
1880 KB |
Output is correct |
9 |
Correct |
1 ms |
1880 KB |
Output is correct |
10 |
Correct |
1 ms |
1880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1964 KB |
Output is correct |
3 |
Correct |
1 ms |
1880 KB |
Output is correct |
4 |
Correct |
1 ms |
1880 KB |
Output is correct |
5 |
Correct |
1 ms |
1880 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
1880 KB |
Output is correct |
8 |
Correct |
1 ms |
1880 KB |
Output is correct |
9 |
Correct |
1 ms |
1880 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
2 ms |
2724 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
3 ms |
2908 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
2792 KB |
Output is correct |
16 |
Correct |
19 ms |
3332 KB |
Output is correct |
17 |
Correct |
2 ms |
2648 KB |
Output is correct |
18 |
Partially correct |
35 ms |
3296 KB |
Partially correct - number of queries: 5296 |
19 |
Correct |
2 ms |
2648 KB |
Output is correct |
20 |
Correct |
6 ms |
1636 KB |
Output is correct |
21 |
Correct |
9 ms |
3020 KB |
Output is correct |
22 |
Correct |
3 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2500 KB |
Output is correct |
24 |
Correct |
2 ms |
2392 KB |
Output is correct |
25 |
Correct |
16 ms |
3620 KB |
Output is correct |
26 |
Correct |
14 ms |
3316 KB |
Output is correct |
27 |
Correct |
1 ms |
1880 KB |
Output is correct |
28 |
Partially correct |
22 ms |
3344 KB |
Partially correct - number of queries: 5020 |
29 |
Correct |
18 ms |
3196 KB |
Output is correct |
30 |
Partially correct |
19 ms |
3264 KB |
Partially correct - number of queries: 5206 |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
4 ms |
2724 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
8 ms |
2968 KB |
Output is correct |
35 |
Correct |
2 ms |
2904 KB |
Output is correct |
36 |
Correct |
8 ms |
2868 KB |
Output is correct |
37 |
Correct |
2 ms |
3108 KB |
Output is correct |
38 |
Correct |
1 ms |
2392 KB |
Output is correct |
39 |
Correct |
11 ms |
2932 KB |
Output is correct |
40 |
Correct |
25 ms |
3220 KB |
Output is correct |
41 |
Correct |
14 ms |
2988 KB |
Output is correct |
42 |
Correct |
15 ms |
3092 KB |
Output is correct |
43 |
Correct |
12 ms |
2976 KB |
Output is correct |
44 |
Correct |
9 ms |
2964 KB |
Output is correct |
45 |
Correct |
6 ms |
2960 KB |
Output is correct |
46 |
Correct |
2 ms |
2648 KB |
Output is correct |
47 |
Correct |
11 ms |
2968 KB |
Output is correct |
48 |
Correct |
18 ms |
3332 KB |
Output is correct |
49 |
Correct |
3 ms |
2648 KB |
Output is correct |
50 |
Partially correct |
22 ms |
3380 KB |
Partially correct - number of queries: 5270 |
51 |
Correct |
10 ms |
2960 KB |
Output is correct |
52 |
Correct |
1 ms |
2648 KB |
Output is correct |
53 |
Correct |
2 ms |
2892 KB |
Output is correct |
54 |
Correct |
10 ms |
3012 KB |
Output is correct |
55 |
Correct |
2 ms |
2648 KB |
Output is correct |
56 |
Partially correct |
26 ms |
3324 KB |
Partially correct - number of queries: 5313 |
57 |
Correct |
21 ms |
3216 KB |
Output is correct |
58 |
Correct |
16 ms |
3344 KB |
Output is correct |
59 |
Correct |
18 ms |
3068 KB |
Output is correct |
60 |
Correct |
9 ms |
3076 KB |
Output is correct |
61 |
Correct |
2 ms |
2892 KB |
Output is correct |
62 |
Correct |
2 ms |
2388 KB |
Output is correct |
63 |
Correct |
2 ms |
2892 KB |
Output is correct |
64 |
Correct |
2 ms |
2636 KB |
Output is correct |
65 |
Incorrect |
2 ms |
4952 KB |
Integer -1 violates the range [0, 199999] |
66 |
Halted |
0 ms |
0 KB |
- |