Submission #1205964

#TimeUsernameProblemLanguageResultExecution timeMemory
1205964banganPacking Biscuits (IOI20_biscuits)C++20
0 / 100
1152 ms1684464 KiB
#include "biscuits.h"
#include <bits/stdc++.h>

using i64 = long long;

long long count_tastiness(long long x, std::vector<long long> a) {
	assert(x == 1);

	for (int i = 0; i < a.size(); i++) {
		if (i + 1 == a.size() && a[i] > 2) {
			a.push_back(0);
		}
		if (a[i] > 2) {
			i64 t = (a[i] - 1) / 2;
			a[i] -= 2 * t;
			a[i + 1] += t;
		}
	}
	
	int k = a.size();
	i64 ans = 1;

	for (int l = 0; l < k;) {
		if (!a[l]) {
			l++;
			continue;
		}

		int r = l;
		while (r < k && a[r] > 0) {
			r++;
		}

		int lst = l - 1;
		for (int i = l; i < r; i++) {
			if (a[i] == 2) {
				lst = i;
			}
		}

		i64 ways = 1LL << (r - l);
		if (lst != l - 1) {
			ways += 1LL << (lst - l);
			ways--;
		}
		ans *= ways;

		l = r;
	}
	std::cout << ans;
}

Compilation message (stderr)

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:50:22: warning: control reaches end of non-void function [-Wreturn-type]
   50 |         std::cout << ans;
      |                      ^~~
#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...