Submission #432517

# Submission time Handle Problem Language Result Execution time Memory
432517 2021-06-18T10:50:08 Z saleh Packing Biscuits (IOI20_biscuits) C++17
12 / 100
1 ms 332 KB
#include "biscuits.h"//
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int MAXK = 60 + 3;

int dp[2][MAXK], pd[MAXK];

long long count_tastiness(long long x, vector<long long> a) {
	if (x != 1) return 0;
	int k = 60;
	while (a.size() < k) a.push_back(0);
	for (int i = 0; i < k; i++) if (a[i] > 0) {
		if (a[i] % 2 == 0) {
			a[i + 1] += a[i] / 2 - 1;
			a[i] = 2;
		} else {
			a[i + 1] += a[i] / 2;
			a[i] = 1;
		}
	}
	pd[0] = 1;
	dp[0][0] = 0;
	dp[1][0] = (a[0] > 0? 1: 0);
	for (int i = 1; i < k; i++) {
		pd[i] = dp[1][i - 1] + pd[i - 1];
		int tmp = i - 1;
		while (tmp > 0 && a[tmp] == 1) tmp--;
		if (a[tmp] == 0 || (tmp == 0 && a[tmp] == 1)) {
			dp[0][i] = 0;
			if (a[i] == 0) dp[1][i] = 0;
			else dp[1][i] = pd[i];
		} else {
			dp[0][i] = dp[0][tmp] + pd[tmp];
			if (a[i] == 0) dp[1][i] = dp[0][i];
			else dp[1][i] = pd[i];
		}
	}
	return dp[1][k - 1] + pd[k - 1];
}

//int32_t main() { cout << count_tastiness(3, {5, 2, 1}); }//

Compilation message

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:15:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   15 |  while (a.size() < k) a.push_back(0);
      |         ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 248 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -