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>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=char(n%10+48);n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}
#ifndef ONLINE_JUDGE
template<typename T>
void pr(T a){std::cerr<<a<<std::endl;}
template<typename T,typename... Args>
void pr(T a, Args... args) {std::cerr<<a<<' ',pr(args...);}
#else
template<typename... Args>
void pr(Args... args){}
#endif
using namespace std;
using ll = long long;
#include <ext/pb_ds/assoc_container.hpp>
__gnu_pbds::gp_hash_table<ll, ll> dp[69];
ll x;
vector<ll> a, sum;
ll go(int i, ll v){
if(i < 0) return !v;
if(sum[i] < v)
return 0;
if(dp[i].find(v) != dp[i].end())
return dp[i][v];
ll add = a[i]*(1LL<<i);
return dp[i][v] = go(i-1, max(0LL, v-add)) + go(i-1, max(0LL, v-add+x*(1LL<<i)));
}
ll count_tastiness(ll _x, vector<ll> _a){
a = _a, x = _x;
a.emplace_back(0);
a.emplace_back(0);
// for(int t = 0; t < 30; t++)
// a.emplace_back(0);
int n = size(a);
sum.resize(n);
for(int i = 0; i < n; i++){
sum[i] = (1LL<<i)*a[i];
if(i) sum[i] += sum[i-1];
}
return go(n-1, 0);
}
#ifdef LOCAL
int main(){
print(count_tastiness(3, {5, 2, 1}));
}
#endif
# | 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... |