#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>
void sort_uniq(vector<T>& v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
ll count_tastiness(ll x, vector<ll> a) {
for (int i = 0; i < a.size(); i++) {
if (a[i] > x) {
ll e = a[i] - x >> 1 << 1;
a[i] -= e;
if (i + 1 == a.size()) a.push_back(0LL);
a[i + 1] += e >> 1;
}
assert(a[i] <= x + 1);
}
ll up = 2*x + 1;
for (ll r = up; r > 0; r >>= 1) a.push_back(0LL);
a.push_back(0LL);
ll val = 0;
vector<ll> ans(1, 1LL), bds(1);
auto g = [&](ll v) {
return v >= 0 ? ans[distance(bds.begin(), upper_bound(bds.begin(), bds.end(), (v >> 1) + val)) - 1] : 0;
};
for (int i = a.size(); i--;) {
vector<ll> bbds(1);
for (ll b : bds) if (b != 1 || x == 1) bbds.push_back(b - val << 1);
for (int i = bbds.size(); i--;) bbds.push_back(bbds[i] + x);
bbds.push_back(1LL);
sort_uniq(bbds);
while (bbds.back() > up) bbds.pop_back();
auto e = bbds.begin();
while (*e < 0) e++;
bbds.erase(bbds.begin(), e);
vector<ll> bans;
for (ll v : bbds) bans.push_back(g(v) + g(v - x));
bds = bbds;
ans = bans;
val = a[i];
}
return g(0);
}
Compilation message
biscuits.cpp: In function 'll count_tastiness(ll, std::vector<long long int>)':
biscuits.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
biscuits.cpp:15:25: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
15 | ll e = a[i] - x >> 1 << 1;
biscuits.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | if (i + 1 == a.size()) a.push_back(0LL);
| ~~~~~~^~~~~~~~~~~
biscuits.cpp:34:65: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
34 | for (ll b : bds) if (b != 1 || x == 1) bbds.push_back(b - val << 1);
| ~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
384 KB |
Output is correct |
2 |
Correct |
231 ms |
896 KB |
Output is correct |
3 |
Correct |
239 ms |
1016 KB |
Output is correct |
4 |
Correct |
231 ms |
888 KB |
Output is correct |
5 |
Correct |
238 ms |
896 KB |
Output is correct |
6 |
Correct |
285 ms |
896 KB |
Output is correct |
7 |
Correct |
276 ms |
888 KB |
Output is correct |
8 |
Correct |
255 ms |
888 KB |
Output is correct |
9 |
Correct |
263 ms |
896 KB |
Output is correct |
10 |
Correct |
230 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
1 ms |
256 KB |
Output is correct |
23 |
Correct |
1 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
1 ms |
256 KB |
Output is correct |
26 |
Correct |
1 ms |
256 KB |
Output is correct |
27 |
Correct |
1 ms |
256 KB |
Output is correct |
28 |
Correct |
1 ms |
256 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
1 ms |
256 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
3 ms |
256 KB |
Output is correct |
35 |
Correct |
3 ms |
256 KB |
Output is correct |
36 |
Correct |
3 ms |
256 KB |
Output is correct |
37 |
Correct |
32 ms |
384 KB |
Output is correct |
38 |
Correct |
231 ms |
896 KB |
Output is correct |
39 |
Correct |
239 ms |
1016 KB |
Output is correct |
40 |
Correct |
231 ms |
888 KB |
Output is correct |
41 |
Correct |
238 ms |
896 KB |
Output is correct |
42 |
Correct |
285 ms |
896 KB |
Output is correct |
43 |
Correct |
276 ms |
888 KB |
Output is correct |
44 |
Correct |
255 ms |
888 KB |
Output is correct |
45 |
Correct |
263 ms |
896 KB |
Output is correct |
46 |
Correct |
230 ms |
896 KB |
Output is correct |
47 |
Correct |
60 ms |
440 KB |
Output is correct |
48 |
Correct |
55 ms |
896 KB |
Output is correct |
49 |
Correct |
37 ms |
384 KB |
Output is correct |
50 |
Correct |
50 ms |
768 KB |
Output is correct |
51 |
Correct |
94 ms |
768 KB |
Output is correct |
52 |
Correct |
31 ms |
384 KB |
Output is correct |
53 |
Correct |
81 ms |
772 KB |
Output is correct |
54 |
Correct |
238 ms |
928 KB |
Output is correct |
55 |
Correct |
235 ms |
896 KB |
Output is correct |
56 |
Correct |
230 ms |
888 KB |
Output is correct |
57 |
Correct |
214 ms |
888 KB |
Output is correct |