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 cs const
#define pb push_back
using namespace std;
typedef long long ll;
cs int N = 64;
ll sm[N], dp[N][N], lm[N];
ll count_tastiness(ll x, vector<ll> a) {
a.resize(61);
memset(sm, 0, sizeof sm);
for(int i = 0; i < 61; i++)
sm[i] = (i ? sm[i - 1] : 0) + (a[i] << i);
for(int i = 0; i < 61; i++) {
lm[i] = sm[i] / x - (1ll << i);
lm[i] = min(lm[i], min((1ll << i) - 1, sm[i - 1]));
}
memset(dp, 0, sizeof dp);
dp[61][61] = 1;
for(ll i = 60, c; ~i; i--) {
// first
dp[i][61] = dp[i + 1][61];
if(lm[i] >= 0) dp[i][i] = dp[i + 1][61];
ll mask = (1ll << i) - 1;
for(int j = i + 1; j <= 60; j++)
if(c = dp[i + 1][j]){
// choose
if((lm[j] >> i & 1) && lm[i] >= 0) {
if((lm[j] & mask) > lm[i])
dp[i][i] += c;
else
dp[i][j] += c;
}
// not choose
if(lm[j] >> i & 1) {
dp[i][61] += c;
}
else {
dp[i][j] += c;
}
}
}
ll ans = 0;
for(int i = 0; i <= 61; i++)
if(lm[i] >= 0) ans += dp[0][i];
// exit(0);
return ans;
}
#ifdef FSYo
int main() {
freopen("1.in", "r", stdin);
int T;
cin >> T;
while(T--) {
ll k, x;
cin >> k >> x;
vector<ll> a(k);
for(int i = 0; i < k; i++)
cin >> a[i];
cout << count_tastiness(x, a) << '\n';
}
return 0;
}
#endif
Compilation message (stderr)
biscuits.cpp: In function 'll count_tastiness(ll, std::vector<long long int>)':
biscuits.cpp:26:8: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
26 | if(c = dp[i + 1][j]){
| ~~^~~~~~~~~~~~~~
# | 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... |