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>
#include <unordered_map>
#include <map>
#include <utility>
#include <functional>
#include <cassert>
#include <set>
#include <random>
using namespace std;
using ll = long long ;
ll x;
vector<ll> a;
map<ll, ll> dp[61];
mt19937 rnd(453);
ll calc(ll rem, ll i) {
if(i>=(int)a.size()) return 1LL<<(rem/x);
auto it=dp[i].lower_bound(rem);
if(it!=dp[i].end() && it->first==rem) return dp[i][rem];
if(it!=dp[i].end() && it!=dp[i].begin()) {
if(it->second==prev(it)->second) {
return it->second;
}
}
ll orig=rem;
if(i<(int)a.size() || rem>=x) {
if(i<(int)a.size()) {
rem+=a[i];
}
ll ans=0;
if(rem>=x) {
if(i&1) {
ans+=calc(rem/2, i+1);
ans+=calc((rem-x)/2, i+1);
}else {
ans+=calc((rem-x)/2, i+1);
ans+=calc(rem/2, i+1);
}
}else {
ans+=calc(rem/2, i+1);
}
return dp[i][orig]=ans;
}else {
return 1;
}
}
ll count_tastiness(ll x_, vector<ll> a_) {
a=a_;
x=x_;
a.resize(60);
for(int i=0;i<60;++i) {
if(a[i]>=x+2) {
ll diff=a[i]-(x+1);
a[i]-=(diff+1)/2*2;
a[i+1]+=(diff+1)/2;
}
}
while(a.back()==0) a.pop_back();
for(auto& i:dp) i.clear();
return calc(0, 0);
}
# | 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... |