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 <bits/stdc++.h>
#include "biscuits.h"
#include <cassert>
#include <cstdio>
#define pb push_back
using namespace std;
typedef long long ll;
//
//#ifdef _WIN32
//# define I64 "%I64d"
//#else
//# define I64 "%lld"
//#endif
//
//long long count_tastiness(long long, std::vector<long long>);
//
//int main () {
// int q;
// assert(scanf("%d", &q) == 1);
// vector<int> k(q);
// vector<long long> x(q);
// vector<vector<long long>> a(q);
// vector<long long> results(q);
// for (int t = 0; t < q; t++) {
// assert(scanf("%d" I64, &k[t], &x[t]) == 2);
// a[t] = vector<long long>(k[t]);
// for (int i = 0; i < k[t]; i++)
// assert(scanf(I64, &a[t][i]) == 1);
// }
// fclose(stdin);
//
// for (int t = 0; t < q; t++)
// results[t] = count_tastiness(x[t], a[t]);
// for (int t = 0; t < q; t++)
// printf(I64 "\n", results[t]);
// fclose(stdout);
// return 0;
//}
long long count_tastiness(long long x, std::vector<long long> a) {
while (a.size() < 60) a.pb(0);
vector <ll> b = a;
for (int i = 1; i < 60; i++) b[i] += b[i - 1] / 2;
ll dp[61];
dp[0] = 1;
for (int i = 0; i < 60; i++)
{
dp[i + 1] = dp[i];
ll need = max(0ll, (x - a[i]) * 2);
for (int j = i - 1; j >= 0; j--)
{
if (b[j] >= x + need)
{
dp[i + 1] += dp[j];
need = max((x + need - a[j]) * 2, 0ll);
}
else need = max((need - a[j]) * 2, 0ll);
}
if (need == 0) dp[i + 1]++;
}
return dp[60];
}
# | 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... |