#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i , j , k) for(int i = j; i < (int)k; i++)
#define all(x) x.begin(),x.end()
typedef vector<int> vi;
map<int , vi> mp;
inline vi F(int i) {
if (mp.count(i)) return mp[i];
if (mp.size() + 1 > 10000) assert(0);
return (mp[i] = ask(i));
}
inline int sum(vi me) {
return accumulate(all(me) , 0);
}
int least, ans;
bitset<400000> mark;
void solve(int l , int r, int le , int ri) {
if (ans != -1) return;
if (l >= r) return;
if (le + ri == least) return;
int mid = l + r >> 1;
bool happy = false;
rep(i , 0 , r - l) {
if (i & 1) mid -= i;
else mid += i;
vi me = F(mid);
mark[mid] = true;
if (sum(me) == 0) ans = mid;
if (sum(me) == least) {
happy = true;
break;
}
}
if (!happy) return;
int ptr = l;
while (!mark[ptr]) ptr++;
int ptr2 = ptr;
while (sum(F(ptr2)) != least) ptr2++;
int ptr3 = r - 1;
while (!mark[ptr3]) ptr3--;
int ptr4 = ptr3;
while (sum(F(ptr4)) != least) ptr4--;
solve(l , ptr , le , ptr2 - ptr + F(ptr2)[1]);
solve(ptr3 + 1 , r , ptr3 - ptr4 + F(ptr4)[0], ri);
}
int find_best(int n) {
mp.clear();
rep(i , 0 , n) mark[i] = false;
least = -1; ans = -1;
for (int i = 1; (i - 2) * (i - 2) <= n; i++) {
least = max(least , sum(F(i - 1)));
if (sum(F(i - 1)) == 0) return i - 1;
}
solve(0 , n , 0 , 0);
return ans;
}
Compilation message
prize.cpp: In function 'void solve(int, int, int, int)':
prize.cpp:30:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
376 KB |
Output is correct |
4 |
Correct |
8 ms |
376 KB |
Output is correct |
5 |
Correct |
8 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
248 KB |
Output is correct |
7 |
Correct |
7 ms |
304 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
568 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
3 |
Correct |
9 ms |
308 KB |
Output is correct |
4 |
Correct |
5 ms |
364 KB |
Output is correct |
5 |
Correct |
8 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
308 KB |
Output is correct |
7 |
Correct |
5 ms |
448 KB |
Output is correct |
8 |
Correct |
7 ms |
396 KB |
Output is correct |
9 |
Correct |
6 ms |
564 KB |
Output is correct |
10 |
Correct |
11 ms |
376 KB |
Output is correct |
11 |
Correct |
7 ms |
396 KB |
Output is correct |
12 |
Correct |
8 ms |
376 KB |
Output is correct |
13 |
Correct |
10 ms |
476 KB |
Output is correct |
14 |
Correct |
6 ms |
252 KB |
Output is correct |
15 |
Correct |
17 ms |
376 KB |
Output is correct |
16 |
Correct |
43 ms |
732 KB |
Output is correct |
17 |
Correct |
8 ms |
376 KB |
Output is correct |
18 |
Correct |
59 ms |
864 KB |
Output is correct |
19 |
Correct |
8 ms |
376 KB |
Output is correct |
20 |
Correct |
20 ms |
424 KB |
Output is correct |
21 |
Correct |
27 ms |
564 KB |
Output is correct |
22 |
Correct |
8 ms |
420 KB |
Output is correct |
23 |
Correct |
9 ms |
376 KB |
Output is correct |
24 |
Correct |
8 ms |
304 KB |
Output is correct |
25 |
Correct |
31 ms |
668 KB |
Output is correct |
26 |
Correct |
36 ms |
604 KB |
Output is correct |
27 |
Correct |
6 ms |
456 KB |
Output is correct |
28 |
Correct |
52 ms |
760 KB |
Output is correct |
29 |
Correct |
32 ms |
748 KB |
Output is correct |
30 |
Correct |
60 ms |
956 KB |
Output is correct |
31 |
Correct |
9 ms |
376 KB |
Output is correct |
32 |
Correct |
14 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
25 ms |
504 KB |
Output is correct |
35 |
Correct |
7 ms |
472 KB |
Output is correct |
36 |
Correct |
20 ms |
648 KB |
Output is correct |
37 |
Correct |
10 ms |
376 KB |
Output is correct |
38 |
Correct |
9 ms |
376 KB |
Output is correct |
39 |
Correct |
29 ms |
548 KB |
Output is correct |
40 |
Correct |
56 ms |
848 KB |
Output is correct |
41 |
Correct |
37 ms |
632 KB |
Output is correct |
42 |
Correct |
23 ms |
720 KB |
Output is correct |
43 |
Correct |
35 ms |
644 KB |
Output is correct |
44 |
Correct |
33 ms |
552 KB |
Output is correct |
45 |
Correct |
27 ms |
504 KB |
Output is correct |
46 |
Correct |
7 ms |
376 KB |
Output is correct |
47 |
Correct |
31 ms |
584 KB |
Output is correct |
48 |
Correct |
45 ms |
636 KB |
Output is correct |
49 |
Correct |
12 ms |
304 KB |
Output is correct |
50 |
Correct |
37 ms |
1028 KB |
Output is correct |
51 |
Correct |
30 ms |
504 KB |
Output is correct |
52 |
Correct |
9 ms |
376 KB |
Output is correct |
53 |
Correct |
10 ms |
436 KB |
Output is correct |
54 |
Correct |
18 ms |
572 KB |
Output is correct |
55 |
Correct |
5 ms |
364 KB |
Output is correct |
56 |
Correct |
45 ms |
820 KB |
Output is correct |
57 |
Correct |
37 ms |
812 KB |
Output is correct |
58 |
Correct |
46 ms |
632 KB |
Output is correct |
59 |
Correct |
37 ms |
656 KB |
Output is correct |
60 |
Correct |
34 ms |
588 KB |
Output is correct |
61 |
Correct |
10 ms |
376 KB |
Output is correct |
62 |
Correct |
9 ms |
376 KB |
Output is correct |
63 |
Correct |
9 ms |
376 KB |
Output is correct |
64 |
Correct |
5 ms |
480 KB |
Output is correct |
65 |
Correct |
8 ms |
376 KB |
Output is correct |
66 |
Correct |
8 ms |
464 KB |
Output is correct |
67 |
Correct |
10 ms |
432 KB |
Output is correct |
68 |
Correct |
5 ms |
372 KB |
Output is correct |
69 |
Correct |
14 ms |
376 KB |
Output is correct |
70 |
Correct |
12 ms |
376 KB |
Output is correct |
71 |
Partially correct |
64 ms |
808 KB |
Partially correct - number of queries: 5207 |
72 |
Correct |
10 ms |
524 KB |
Output is correct |
73 |
Partially correct |
62 ms |
888 KB |
Partially correct - number of queries: 5144 |
74 |
Partially correct |
70 ms |
888 KB |
Partially correct - number of queries: 5171 |
75 |
Correct |
11 ms |
396 KB |
Output is correct |
76 |
Correct |
61 ms |
888 KB |
Output is correct |
77 |
Correct |
64 ms |
932 KB |
Output is correct |
78 |
Correct |
15 ms |
376 KB |
Output is correct |
79 |
Correct |
32 ms |
568 KB |
Output is correct |
80 |
Correct |
63 ms |
808 KB |
Output is correct |
81 |
Correct |
66 ms |
956 KB |
Output is correct |
82 |
Correct |
63 ms |
892 KB |
Output is correct |
83 |
Correct |
9 ms |
376 KB |
Output is correct |
84 |
Correct |
53 ms |
760 KB |
Output is correct |
85 |
Correct |
57 ms |
760 KB |
Output is correct |
86 |
Runtime error |
117 ms |
2656 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
87 |
Halted |
0 ms |
0 KB |
- |