# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1207959 | Cyanmond | Packing Biscuits (IOI20_biscuits) | C++20 | 0 ms | 0 KiB |
#include "biscuits.h"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int n = 63;
ll a[64], dp[64];
long long count_tastiness(long long x, std::vector<long long> a_) {
for (int i = 0; i < int(a.size()); ++i) {
a[i] = a_[i];
}
for (int i = 0; i < n; ++i) {
if (a[i] > x + 1) {
ll diff = a[i] - (x + 1);
ll div = (diff + 1) / 2;
a[i] -= div * 2;
a[i + 1] += div;
}
}
a.push_back(0);
reverse(a.begin(), a.end());
fill(dp, dp + n + 1, 0);
dp[0] = 1;
for (int i = 0; i < n; ++i) {
// case 1: no
dp[i + 1] += dp[i];
// case 2: yes
if (a[i] >= x) {
dp[i + 1] += dp[i];
continue;
}
ll lack = x;
for (int j = i; j < n; ++j) {
lack -= a[j];
if (lack <= 0) {
dp[j + 1] += dp[i];
lack += x;
}
lack *= 2;
if (lack > 3 * x) {
break;
}
}
}
return dp[n];
}