public class biscuits {
long count_tastiness(long x, long[] a) {
if (x == 1) {
return solveXIsOne(a);
}
return countNaive(x, a);
}
// How many diff. sums can we get by (n[i] * 2^i, where 0 <= n[i] <= a[i]).
long solveXIsOne(long[] a) {
return recursiveXIsOne(0, 0, a);
}
long recursiveXIsOne(int pos, long first, long[] a) {
if (pos == a.length - 1) {
return first + 1;
}
long res = recursiveXIsOne(pos + 1, a[pos + 1] + first / 2, a);
if (first > 0) {
res += recursiveXIsOne(pos + 1, a[pos + 1] + (first - 1) / 2, a);
}
return res;
}
long countNaive(long x, long[] a) {
return countRec(x, a, 0);
}
long countRec(long x, long[] a, int index) {
if (index == a.length - 1) {
return a[a.length - 1] / x + 1;
}
long temp = a[index + 1];
a[index + 1] = a[index + 1] + a[index] / 2;
long answer = countRec(x, a, index + 1);
if (a[index] >= x) {
a[index + 1] = temp + (a[index] - x) / 2;
answer += countRec(x, a, index + 1);
a[index + 1] = temp;
}
a[index + 1] = temp;
return answer;
}
}
// (s[k-1] - i * X) / (2^(k-1)), 0 <= i < 2^(k - 1).
// For which i is this state valid?
// If for each position b s.t. b-th bit is set in i, (s[b+1] - (2^b + prev(i,b))X) / 2^(b+1) >= X.
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
10232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
10100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
90 ms |
10416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
10876 KB |
Output is correct |
2 |
Execution timed out |
1020 ms |
11036 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
10232 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |