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;
ll x;
vector<ll> a, sum;
ll go(ll v){
if(v < 0)
return 0;
if(v == 0)
return 1;
if(dp.find(v) != dp.end())
return dp[v];
int i = __lg(v);
dp[v] = go((1LL<<i)-1) + go(min(v, sum[i]/x)-(1LL<<i));
// pr(v, dp[v]);
return dp[v];
}
ll count_tastiness(ll _x, vector<ll> _a){
a = _a, x = _x;
while(size(a) < 60)
a.emplace_back(0);
int n = size(a);
dp.clear();
sum.clear();
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((1LL<<60)-1);
}
#ifdef LOCAL
int main(){
print(count_tastiness(3, {5, 2, 1}));
return 0;
int q, n, xx;
scan(q);
while(q--){
scan(n, xx);
vector<ll> aa(n);
for(auto &i: aa)
scan(i);
print(count_tastiness(xx, aa));
}
}
#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... |