이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
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(){
string s;
cin>>s;
// print(count_tastiness(3, {5, 2, 1}));
int q, n, xx;
scan(q);
while(q--){
dp.clear();
sum.clear();
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... |