Submission #303520

#TimeUsernameProblemLanguageResultExecution timeMemory
303520tutisPacking Biscuits (IOI20_biscuits)C++17
12 / 100
1100 ms20780 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll count_tastiness(ll x, vector<ll> a)
{
	while (a.size() < 60)
		a.push_back(0);
	ll s[61];
	for (int i = 0; i <= 60; i++)
		s[i] = 0;
	for (int t = 1; t <= 60; t++)
	{
		s[60 - t] = s[60 - t + 1] + a[60 - t];
		if (s[60 - t] >= x)
			s[60 - t] -= x;
		for (int i = 0; i < 60; i++)
		{
			s[i] *= 2;
			if (s[i] >= x)
				s[i] -= x;
		}
	}
	map<ll, ll>M[130];
	function<ll(ll, int)>get = [&](ll d, int i)->ll
	{
		if (i == 60)
			return d / x + 1;
		if (a[i] + d < x)
		{
			ll dd = (s[i] + d) % x;
			d -= dd;
			if (M[i].count(d))
				return M[i][d];
			return M[i][d] = get((d + a[i]) / 2, i + 1);
		}
		else
		{
			if (M[i].count(d))
				return M[i][d];
			return M[i][d] = get((d + a[i]) / 2, i + 1) + get((d + a[i] - x) / 2, i + 1);
		}
	};
	return get(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...