Submission #558399

#TimeUsernameProblemLanguageResultExecution timeMemory
558399ymmPacking Biscuits (IOI20_biscuits)C++17
33 / 100
39 ms5240 KiB
///
///   Standing here
///   I realize
///   You are just like me
///   Trying to make history
///

#include <bits/stdc++.h>
#define Loop(x,l,r) for(ll x = ll(l); x < ll(r); ++x)
#define LoopR(x,l,r) for(ll x = ll(r)-1; x >= ll(l); --x)
#define Kill(x) exit((cout << (x) << '\n', 0))
typedef long long ll;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
using namespace std;

#ifndef LOCAL
#include "biscuits.h"
#else
ll count_tastiness(ll, vector<ll>);
int main()
{
	cout << count_tastiness(3, {5, 2, 1}) << '\n';
}
#endif


const int K = 63, X = 10010;
ll mm[K][X], a[K];
ll x;

ll solve(int i, ll rem)
{
	if (i == K)
		return rem/x + 1;
	if (mm[i][rem] != -1)
		return mm[i][rem];
	ll ans = solve(i+1, (rem+a[i])/2);
	if (rem + a[i] >= x)
		ans += solve(i+1, (rem+a[i]-x)/2);
	return mm[i][rem] = ans;
}

ll count_tastiness(ll _x, vector<ll> _a)
{
	assert(_x <= 10000);
	x = _x; _a.resize(K);
	memset(mm, -1, sizeof(mm));
	memset(a, 0, sizeof(a));
	Loop (i,0,K-1) {
		a[i] += _a[i];
		if (a[i] > x) {
			ll y = (a[i]-x)/2;
			a[i+1] += y;
			a[i] -= y*2;
		}
	}
	return solve(0, 0);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...