#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500;
int find_best(int n)
{
vector<vector<int> > store(n + 1, vector<int> (2));
for(int i = 0; i <= n; i++)
{
store[i][0] = -1;
store[i][1] = -1;
}
int previous_optimal = -1;
store[0] = ask(0);
if(store[0][0] == 0 && store[0][1] == 0)
{
return 0;
}
int max_sum = store[0][0] + store[0][1];
for(int atleastbefore = 1; atleastbefore <= n; atleastbefore++)
{
int l = 0, r = n - 1;
int current_optimal = 0;
while(l < r)
{
int mid = (l + r) / 2;
// cout << "l = " << l << ", r = " << r << ", previous_optimal = " << previous_optimal << "\n";
if(mid <= previous_optimal)
{
l = mid + 1;
current_optimal = mid + 1;
continue;
}
if(store[mid][0] == -1)
{
store[mid] = ask(mid);
}
if(store[mid][0] + store[mid][1] == 0)
{
return mid;
}
if(store[mid][0] + store[mid][1] > max_sum)
{
max_sum = store[mid][0] + store[mid][1];
l = 0, r = n - 1;
current_optimal = 0;
continue;
}
if(store[mid][0] < atleastbefore && store[mid][0] + store[mid][1] == max_sum)
{
l = mid + 1;
current_optimal = mid + 1;
}
else
{
r = mid;
}
}
assert(current_optimal >= 0 && current_optimal < n);
previous_optimal = current_optimal;
if(store[previous_optimal][0] == -1)
{
store[previous_optimal] = ask(previous_optimal);
}
if(store[previous_optimal][0] + store[previous_optimal][1] == 0)
{
return previous_optimal;
}
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
11164 KB |
Output is correct |
2 |
Correct |
12 ms |
11208 KB |
Output is correct |
3 |
Correct |
13 ms |
11188 KB |
Output is correct |
4 |
Correct |
13 ms |
11216 KB |
Output is correct |
5 |
Correct |
12 ms |
11176 KB |
Output is correct |
6 |
Correct |
12 ms |
11140 KB |
Output is correct |
7 |
Correct |
12 ms |
11172 KB |
Output is correct |
8 |
Correct |
12 ms |
11208 KB |
Output is correct |
9 |
Correct |
16 ms |
11168 KB |
Output is correct |
10 |
Correct |
14 ms |
11216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
11168 KB |
Output is correct |
2 |
Correct |
12 ms |
11168 KB |
Output is correct |
3 |
Correct |
12 ms |
11176 KB |
Output is correct |
4 |
Correct |
12 ms |
11216 KB |
Output is correct |
5 |
Correct |
13 ms |
11168 KB |
Output is correct |
6 |
Correct |
12 ms |
11216 KB |
Output is correct |
7 |
Correct |
12 ms |
11168 KB |
Output is correct |
8 |
Correct |
12 ms |
11216 KB |
Output is correct |
9 |
Correct |
12 ms |
11176 KB |
Output is correct |
10 |
Correct |
13 ms |
11216 KB |
Output is correct |
11 |
Correct |
12 ms |
11164 KB |
Output is correct |
12 |
Correct |
12 ms |
11216 KB |
Output is correct |
13 |
Correct |
16 ms |
11160 KB |
Output is correct |
14 |
Correct |
3 ms |
1360 KB |
Output is correct |
15 |
Correct |
16 ms |
11160 KB |
Output is correct |
16 |
Correct |
37 ms |
11148 KB |
Output is correct |
17 |
Correct |
12 ms |
11240 KB |
Output is correct |
18 |
Correct |
63 ms |
11128 KB |
Output is correct |
19 |
Correct |
13 ms |
11168 KB |
Output is correct |
20 |
Correct |
16 ms |
5668 KB |
Output is correct |
21 |
Correct |
31 ms |
11212 KB |
Output is correct |
22 |
Correct |
22 ms |
11172 KB |
Output is correct |
23 |
Correct |
13 ms |
11160 KB |
Output is correct |
24 |
Correct |
12 ms |
11208 KB |
Output is correct |
25 |
Correct |
22 ms |
11164 KB |
Output is correct |
26 |
Correct |
28 ms |
11168 KB |
Output is correct |
27 |
Correct |
13 ms |
11164 KB |
Output is correct |
28 |
Correct |
56 ms |
11132 KB |
Output is correct |
29 |
Correct |
34 ms |
11208 KB |
Output is correct |
30 |
Correct |
50 ms |
11176 KB |
Output is correct |
31 |
Correct |
12 ms |
11208 KB |
Output is correct |
32 |
Correct |
14 ms |
11216 KB |
Output is correct |
33 |
Correct |
0 ms |
208 KB |
Output is correct |
34 |
Correct |
24 ms |
11172 KB |
Output is correct |
35 |
Correct |
12 ms |
11152 KB |
Output is correct |
36 |
Correct |
22 ms |
11172 KB |
Output is correct |
37 |
Correct |
14 ms |
11224 KB |
Output is correct |
38 |
Correct |
12 ms |
11164 KB |
Output is correct |
39 |
Correct |
33 ms |
11156 KB |
Output is correct |
40 |
Correct |
36 ms |
11164 KB |
Output is correct |
41 |
Correct |
33 ms |
11164 KB |
Output is correct |
42 |
Correct |
31 ms |
11164 KB |
Output is correct |
43 |
Correct |
34 ms |
11164 KB |
Output is correct |
44 |
Correct |
26 ms |
11164 KB |
Output is correct |
45 |
Correct |
22 ms |
11216 KB |
Output is correct |
46 |
Correct |
12 ms |
11160 KB |
Output is correct |
47 |
Correct |
24 ms |
11248 KB |
Output is correct |
48 |
Correct |
55 ms |
11164 KB |
Output is correct |
49 |
Correct |
15 ms |
11204 KB |
Output is correct |
50 |
Correct |
50 ms |
11164 KB |
Output is correct |
51 |
Correct |
28 ms |
11156 KB |
Output is correct |
52 |
Correct |
15 ms |
11152 KB |
Output is correct |
53 |
Correct |
15 ms |
11164 KB |
Output is correct |
54 |
Correct |
21 ms |
11140 KB |
Output is correct |
55 |
Correct |
13 ms |
11216 KB |
Output is correct |
56 |
Correct |
58 ms |
11160 KB |
Output is correct |
57 |
Correct |
32 ms |
11168 KB |
Output is correct |
58 |
Correct |
38 ms |
11152 KB |
Output is correct |
59 |
Correct |
37 ms |
11172 KB |
Output is correct |
60 |
Correct |
31 ms |
11164 KB |
Output is correct |
61 |
Correct |
17 ms |
11152 KB |
Output is correct |
62 |
Correct |
12 ms |
11160 KB |
Output is correct |
63 |
Correct |
15 ms |
11148 KB |
Output is correct |
64 |
Correct |
13 ms |
11216 KB |
Output is correct |
65 |
Correct |
13 ms |
11168 KB |
Output is correct |
66 |
Correct |
15 ms |
11164 KB |
Output is correct |
67 |
Correct |
12 ms |
11196 KB |
Output is correct |
68 |
Correct |
13 ms |
11164 KB |
Output is correct |
69 |
Correct |
17 ms |
11168 KB |
Output is correct |
70 |
Correct |
12 ms |
11168 KB |
Output is correct |
71 |
Correct |
53 ms |
11168 KB |
Output is correct |
72 |
Correct |
15 ms |
11248 KB |
Output is correct |
73 |
Correct |
42 ms |
11216 KB |
Output is correct |
74 |
Correct |
35 ms |
11216 KB |
Output is correct |
75 |
Correct |
13 ms |
11152 KB |
Output is correct |
76 |
Correct |
46 ms |
11268 KB |
Output is correct |
77 |
Correct |
43 ms |
11216 KB |
Output is correct |
78 |
Correct |
16 ms |
11216 KB |
Output is correct |
79 |
Correct |
26 ms |
11140 KB |
Output is correct |
80 |
Correct |
52 ms |
11256 KB |
Output is correct |
81 |
Correct |
38 ms |
11216 KB |
Output is correct |
82 |
Correct |
46 ms |
11216 KB |
Output is correct |
83 |
Correct |
12 ms |
11216 KB |
Output is correct |
84 |
Correct |
39 ms |
11168 KB |
Output is correct |
85 |
Correct |
49 ms |
11216 KB |
Output is correct |
86 |
Correct |
45 ms |
11268 KB |
Output is correct |
87 |
Correct |
15 ms |
11172 KB |
Output is correct |
88 |
Correct |
36 ms |
11244 KB |
Output is correct |
89 |
Correct |
46 ms |
11248 KB |
Output is correct |
90 |
Correct |
14 ms |
11188 KB |
Output is correct |
91 |
Correct |
32 ms |
11168 KB |
Output is correct |
92 |
Correct |
60 ms |
11192 KB |
Output is correct |
93 |
Correct |
14 ms |
11204 KB |
Output is correct |
94 |
Correct |
17 ms |
11216 KB |
Output is correct |
95 |
Correct |
15 ms |
11172 KB |
Output is correct |
96 |
Correct |
14 ms |
11216 KB |
Output is correct |
97 |
Correct |
12 ms |
11216 KB |
Output is correct |