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"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll X;
unordered_map<ll,ll>dp[61];
vector<ll>a;
int k;
ll rec(int pos,ll cur){
//assert(cur<2*X);
if(pos==k)return cur/X;
if(dp[pos].find(cur)!=dp[pos].end())return dp[pos][cur];
ll ret=!!((a[pos] + cur) / X);
ret+=rec(pos+1,(cur+a[pos])/2);
if(a[pos]+cur>=X)ret+=rec(pos+1,(a[pos]+cur-X)/2);
return dp[pos][cur]=ret;
}
long long count_tastiness(long long x, vector<long long> A) {
X=x;a=A;k=int(A.size());
for(int i=0;i<61;i++)dp[i].clear();
/*
while(int(a.size())<61)a.pb(0);
for(int i=0;i<60;i++)
if(a[i]>x){
ll tmp=(a[i]-x)/2;
a[i+1]+=tmp;
a[i]-=tmp<<1;
}*/
return rec(0,0)+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... |