#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
int n;
/*
long long Solve(int i, vector<long long> cnt) {
if (i == (int)cnt.size()) {
return 1LL;
}
if (cnt[i] > n + 1) {
if (i + 1 == (int)cnt.size()) {
cnt.emplace_back(0LL);
}
auto delta = (cnt[i] - n) / 2;
cnt[i + 1] += delta;
cnt[i] -= 2 * delta;
}
if (cnt[i] < n) {
return Solve(i + 1, cnt);
}
long long ret = Solve(i + 1, cnt);
if (i + 1 == (int)cnt.size()) {
cnt.emplace_back(0LL);
}
cnt[i + 1] += cnt[i] / 2;
ret += Solve(i + 1, cnt);
return ret;
}
long long Solve(int i, vector<long long> cnt, long long s) {
if (i == (int)cnt.size()) {
// cerr << "br 1: " << s << '\n';
return 1LL;
}
if (i == (int)cnt.size()) {
// cerr << "b: " << s << '\n';
return Solve(i + 1, cnt, s - (n << i));
}
if (cnt[i] < n) {
long long ret = Solve(i + 1, cnt, s + (cnt[i] << i));
if (s + (cnt[i] << i) >= (n << i)) {
ret += Solve(i + 1, cnt, s + (cnt[i] << i) - (n << i));
}
return ret;
}
long long ret = Solve(i + 1, cnt, s + ((cnt[i] - n) << i));
ret += Solve(i + 1, cnt, s + (cnt[i] << i));
// cerr << i << ' ' << s << ' ' << ret << endl;
return ret;
}
*/
bool Try(long long val, const vector<long long> &a) {
long long s = 0;
for (int i = 0; i < (int)a.size(); ++i) {
s += a[i] << i;
if (val & (1LL << i)) {
if (s < (n << i)) {
return false;
}
s -= n << i;
}
}
// cerr << val << ' ' << s << endl;
return true;
}
long long count_tastiness(long long n, vector<long long> a) {
::n = n;
long long s = 0;
for (int i = 0; i < (int)a.size(); ++i) {
if (a[i] > n + 1) {
if (i + 1 == (int)a.size()) a.emplace_back(0LL);
auto delta = (a[i] - n) / 2;
a[i + 1] += delta;
a[i] -= 2 * delta;
}
s += a[i] << i;
// cerr << a[i] << ' ';
}
// cerr << endl;
long long ans = 0;
for (long long i = 0; i * n <= s; ++i) {
ans += Try(i, a);
}
return ans;
// return Solve(0, a, 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
12 ms |
296 KB |
Output is correct |
5 |
Correct |
3 ms |
204 KB |
Output is correct |
6 |
Correct |
31 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
31 ms |
204 KB |
Output is correct |
9 |
Correct |
4 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
19 ms |
212 KB |
Output is correct |
13 |
Correct |
9 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
304 KB |
Output is correct |
2 |
Execution timed out |
1088 ms |
204 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1083 ms |
296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
12 ms |
296 KB |
Output is correct |
5 |
Correct |
3 ms |
204 KB |
Output is correct |
6 |
Correct |
31 ms |
204 KB |
Output is correct |
7 |
Correct |
2 ms |
204 KB |
Output is correct |
8 |
Correct |
31 ms |
204 KB |
Output is correct |
9 |
Correct |
4 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
19 ms |
212 KB |
Output is correct |
13 |
Correct |
9 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
9 ms |
304 KB |
Output is correct |
16 |
Execution timed out |
1088 ms |
204 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |