Submission #304295

#TimeUsernameProblemLanguageResultExecution timeMemory
304295shenxyPacking Biscuits (IOI20_biscuits)C++17
100 / 100
18 ms896 KiB
#include "biscuits.h"
#include <algorithm>
#include <vector>
using namespace std;
long long count_tastiness(long long x, vector<long long> a) {
	while (a.size() < 60) a.push_back(0);
	vector<long long> b;
	for (long long i: a) b.push_back(i);
	for (int i = 1; i < 60; ++i) b[i] += b[i - 1] / 2;
	long long dp[61];
	dp[0] = 1;
	for (int i = 0; i < 60; ++i) {
		if (b[i] < x) {
			dp[i + 1] = dp[i];
			continue;
		}
		long long dpv = 0, k = max(0LL, x - a[i]) * 2;
		for (int j = i; j > 0; --j) {
			if (b[j - 1] >= k + x) dpv += dp[j - 1], k = max(0LL, k + x - a[j - 1]) * 2;
			else k = max(0LL, k - a[j - 1]) * 2;
		}
		if (k == 0) ++dpv;
		dp[i + 1] = dp[i] + dpv;
	}
	return dp[60];
}
#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...