Submission #1206043

#TimeUsernameProblemLanguageResultExecution timeMemory
1206043banganPacking Biscuits (IOI20_biscuits)C++20
100 / 100
8 ms1148 KiB
#include "biscuits.h"
#include <bits/stdc++.h>

using i64 = long long;

long long count_tastiness(long long x, std::vector<long long> a) {
	std::vector<i64> pre = a;
	for (int i = 0; i + 1 < pre.size(); i++) {
		pre[i + 1] += pre[i] / 2;
	}
	while (pre.back() > 1) {
		pre.push_back(pre.back() / 2);
	}

	int k = pre.size();
	while (a.size() < k) {
		a.push_back(0);
	}

	std::vector<i64> dp(k + 1);
	dp[0] = 1;

	for (int i = 0; i < k; i++) {
		dp[i + 1] = dp[i];
		if (pre[i] < x) {
			continue;
		}

		i64 req = 2 * std::max(0LL, x - a[i]);
		for (int j = i - 1; j >= 0; j--) {
			if (pre[j] >= req + x) {
				dp[i + 1] += dp[j];
				req = 2 * std::max(0LL, req + x - a[j]);
			} else {
				req = 2 * std::max(0LL, req - a[j]);
			}
		}

		// if (req == 0) {
			dp[i + 1]++;
		// }
	}
	return dp[k];
}
#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...