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>
#include "biscuits.h"
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9 + 7, INF = 1e18;
ll mod(ll x, ll m = MOD) {return (x + m) % m;}
int n;
ll x, tot = 0ll;
vll A;
bool check(ll s)
{
vll B = A;
for(int i =0; i < x; i++)
{
ll cur = s;
for(int j = n - 1; j >= 0; j--)
{
ll q = min(B[j], cur/(1 << j));
cur -= q * (1 << j);
B[j] -= q;
}
if(cur > 0)
return false;
}
return true;
}
ll sub1()
{
int ans = 0;
for(int i =0; i <= tot/x; i++)
{
if(i == 0 || check(i))
ans++;
}
return ans;
}
map<ll,ll> dp[100];
ll f(int i, ll sum)
{
if(i == n - 1)
return 1ll;
if(dp[i].find(sum) != dp[i].end())
return dp[i][sum];
if(sum > 0)
return dp[i][sum] = f(i + 1, sum/2ll + A[i + 1]) + f(i + 1, (sum - 1)/2ll + A[i + 1]);
else
return dp[i][sum] = f(i + 1, A[i + 1]);
}
ll count_tastiness(ll X, vll a)
{
x = X;
A = a;
n = (int)(a.size());
for(int i =0; i < n; i++)
tot += a[i] * (1 << i);
if(tot <= 1000000)
return sub1();
while(n < 100)
{
A.pb(0ll);
n++;
}
return f(0, a[0]);
}
/*
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << count_tastiness(1, {2, 1, 2});
}
*/
# | 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... |