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 <iostream>
#define int long long
#define lint __int128
using namespace std;
int count_tastiness(int x, vector<int> a)
{
const int m = 64;
vector<int> pref_dp(m);
vector<int> dp(m);
vector<lint> avs(m);
dp[0] = 1;
a.resize(m);
avs[0] = 0;
lint pw = 1;
for (int i = 0; i < m - 1; i++, pw *= 2)
{
avs[i + 1] = avs[i] + pw * (lint)a[i];
}
// cerr << 0 << " " << dp[0] << "\n";
pw = 1;
for (int i = 1; i < m; i++, pw *= 2)
{
pref_dp[i] = dp[i - 1] + pref_dp[i - 1];
if (avs[i] < pw*x) continue;
lint b = avs[i] - pw*x;
lint np = pw / 2;
// cerr << "Starting " << i << " with " << avs[i] << ", after subtracting " << b << "\n";
for (int j = i - 1; j >= 0; j--, np /= 2)
{
b = min(b, avs[j]);
// cerr << " -> " << j << " " << b << " " << np << "\n";
if (b >= np * x)
{
dp[i] += pref_dp[j];
b -= np*x;
}
}
if (b >= 0) dp[i]++;
// cerr << i << " " << dp[i] << "\n";
}
return dp[m - 1] + pref_dp[m - 1];
}
# | 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... |