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>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
const long long mod=1e9+7;
long long x,sum;
int k;
vector<long long> br,total;
long long dp[100][100007];
int li[100][100007],tim;
long long ff(int bit,int rem){
if(bit==-1)return 1;
if(bit==0 and br[0]-rem>=x)return 2;
else if(bit==0)return 1;
if(li[bit][rem]==tim)return dp[bit][rem];
li[bit][rem]=tim;
dp[bit][rem]=ff(bit-1,0);
if(total[bit]-rem>=x){
long long curr=max(x-(br[bit]-rem),0LL)*2;
for(int i=bit-1;i>=0;i--){
if(curr<=br[i]){
dp[bit][rem]+=ff(i,curr);
break;
}else{
curr-=br[i]; curr*=2;
}
}
}
return dp[bit][rem];
}
long long count_tastiness(long long X,vector<long long> a){
k=int(a.size()); x=X;
br.resize(70); total.resize(70);
for(int i=0;i<k;i++){
br[i]=a[i];
total[i]=a[i];
if(i>0)total[i]+=total[i-1]/2;
}
for(int i=k;i<62;i++){
total[i]=total[i-1]/2;
}
tim++;
return ff(61,0);
}
/*
int main(){
cout<<count_tastiness(2, {2, 1, 2})<<"\n";
cout<<count_tastiness(2, {2, 1, 2})<<"\n";
}
*/
# | 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... |