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 "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define int long long
#define pb push_back
#define ins insert
#define sz(x) (int)((x).size())
long long count_tastiness(long long x, std::vector<long long> b) {
while (sz(b) < 60) b.push_back(0);
int lim [60+1];
int sum = 0;
for (int i = 0; i < 60; i++) {
sum += (1LL<<i)*b[i];
lim[i] = min(sum/x, (1LL<<(i+1))-1);
}
lim[60] = (1LL<<60)-1;
int dp [60][60+1];
for (int i = 0; i <= 60; i++) {
if (lim[0] == 0 || (lim[i]&1) == 0) {
dp[0][i] = 1;
}
else {
dp[0][i] = 2;
}
}
for (int i = 1; i < 60; i++) for (int j = 0; j <= 60; j++) {
int resultingMask = (1LL<<(i))-1;
dp[i][j] = 0;
if (((lim[i]>>i)&1) && ((lim[j]>>i)&1)) {
int newJ = j;
if ((lim[i]&resultingMask) < (lim[j]&resultingMask)) {
newJ = i;
}
dp[i][j] += dp[i-1][newJ]; // add one
dp[i][j] += dp[i-1][60]; // add zero
}
else if (!((lim[i]>>i)&1) && !((lim[j]>>i)&1)) {
int newJ = j;
if ((lim[i]&resultingMask) < (lim[j]&resultingMask)) {
newJ = i;
}
dp[i][j] += dp[i-1][newJ]; // add zero
}
else if ((lim[i]>>i)&1) {
dp[i][j] += dp[i-1][j];
}
else {
dp[i][j] += dp[i-1][i];
}
}
int res = dp[60-1][60];
return res;
}
# | 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... |