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>
using namespace std;
const long long mod=1e9+7;
long long x,sum;
int k;
vector<long long> br,toadd;
unordered_map<long long,long long> dp;
long long brute(int bit,long long total,int pos,vector<long long> br){
if(bit==-1)return 1;
long long hesh=(total%mod)*100+bit;
if(dp[hesh]>0)return dp[hesh];
long long curr=br[bit];
total-=curr*(1LL<<bit); br[bit]=0;
long long res=brute(bit-1,total,pos,br);
total+=curr*(1LL<<bit); br[bit]=curr;
curr=x;
if(total>=x*(1LL<<bit)){
total-=x*(1LL<<bit);
for(int i=bit;i>=0;i--){
if(br[i]>=curr){
br[i]-=curr;
curr=0; pos=i; break;
}else{
curr-=br[i];
br[i]=0; curr*=2;
pos=i-1;
}
}
total-=br[bit]*(1LL<<bit); br[bit]=0;
res+=brute(bit-1,total,pos,br);
}
dp[hesh]=res;
return res;
}
long long count_tastiness(long long X,vector<long long> A){
k=int(A.size()); x=X; sum=0; dp.clear();
br.resize(62); toadd.resize(62);
for(int i=0;i<k;i++){
br[i]=A[i];
sum+=br[i]*(1LL<<i);
}
return brute(61,sum,61,br);
}
/*
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... |