This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "biscuits.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(x...) qqbx(#x, x)
template <typename ...T> void qqbx(const char *s, T ...args) {
int cnt = sizeof...(T);
((std::cerr << "\e[1;32m(" << s << ") = (") , ... , (std::cerr << args << (--cnt ? ", " : ")\e[0m\n")));
}
#else
#define debug(...) ((void)0)
#endif
using namespace std;
const int maxn = 65;
map<long long, long long> dp[maxn];
int cnt = 0;
long long dfs(vector<long long> &a, long long x, int i, long long carry) {
if (i == a.size()) {
return carry / x + 1;
}
++cnt;
if (dp[i].count(carry))
return dp[i][carry];
long long &res = dp[i][carry];
carry += a[i];
long long sum = carry;
for (int j = i+1; j < a.size(); j++) sum += a[j] << (j - i);
if (sum < x) {
debug(i, carry, sum);
return res = 1;
}
res += dfs(a, x, i+1, carry / 2); // y >> i & 1 == 0
if (carry >= x) {
res += dfs(a, x, i+1, (carry - x) / 2);
}
return res;
}
long long count_tastiness(long long x, std::vector<long long> a) {
for (int i = 0; i < a.size(); i++) dp[i].clear();
for (int i = 0; i+1 < a.size(); i++) {
if (a[i] >= x) {
long long diff = (a[i] - x) / 2;
a[i] -= diff * 2;
a[i+1] += diff;
}
}
long long res = dfs(a, x, 0, 0);
return res;
}
Compilation message (stderr)
biscuits.cpp: In function 'long long int dfs(std::vector<long long int>&, long long int, int, long long int)':
biscuits.cpp:18:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if (i == a.size()) {
| ~~^~~~~~~~~~~
biscuits.cpp:27:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int j = i+1; j < a.size(); j++) sum += a[j] << (j - i);
| ~~^~~~~~~~~~
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int i = 0; i < a.size(); i++) dp[i].clear();
| ~~^~~~~~~~~~
biscuits.cpp:40:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i+1 < a.size(); i++) {
| ~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |