Submission #305755

#TimeUsernameProblemLanguageResultExecution timeMemory
305755arthurconmy비스킷 담기 (IOI20_biscuits)C++14
0 / 100
54 ms31480 KiB
#ifndef ARTHUR_LOCAL
	#include "biscuits.h"
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define len(x) int((x).size())

ll dp[81][40001];

ll count_tastiness(ll x, vector<ll> A) 
{
	while(len(A) <= 100) A.push_back(0LL);

	for(int i=0; i<len(A); i++)
	{
		if(A[i] > x)
		{
			ll pass_up = ll((A[i]-x)/2LL);
			A[i] -= 2LL*pass_up; // -= pass_up;
			A[i+1] += pass_up;
			// A[i] = x;
		}
	}

	// cout << A[0] << endl;

	dp[0][0] = 1;

	for(int b=0; b<=99; b++)
	{
		// transition up from dp[b] using 1<<b

		// case 1: don't add the zero

		// if(dp[b][i] != 0) cout << b << " " << i << " " << dp[b][i] << endl;

		for(int i=0; i<=40000; i++)
		{
			// if(dp[b][i] != 0) cout << b << " " << i << " " << dp[b][i] << endl;

			dp[b+1][int(i/2) + A[b]] += dp[b][i];
			// if(dp[b+1][int(i/2) + A[b]])
		}

		for(int i=0; i<=40000; i++)
		{
			if(A[b] + int(i/2) >= x)
			{
				dp[b+1][int(i/2) + A[b] - x] += dp[b][i];
			}
		}
	}

	ll ans=0LL;

	for(int i=0; i<=40000; i++)
	{
		ans += dp[100][i];
	}

	return ans;
}

#ifdef ARTHUR_LOCAL
int main()
{
	cout << count_tastiness(3, {5, 2, 1}) << endl;
}
#endif

Compilation message (stderr)

biscuits.cpp: In function 'll count_tastiness(ll, std::vector<long long int>)':
biscuits.cpp:62:16: warning: array subscript 100 is above array bounds of 'll [81][40001]' {aka 'long long int [81][40001]'} [-Warray-bounds]
   62 |   ans += dp[100][i];
      |          ~~~~~~^
cc1plus: warning: iteration 80 invokes undefined behavior [-Waggressive-loop-optimizations]
biscuits.cpp:33:16: note: within this loop
   33 |  for(int b=0; b<=99; b++)
      |               ~^~~~
#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...