Submission #1175565

#TimeUsernameProblemLanguageResultExecution timeMemory
1175565hyakupPacking Biscuits (IOI20_biscuits)C++20
0 / 100
1 ms396 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const ll inf = 1e18 + 10;
const int maxn = 61;
const int maxx = 2e4;

ll dp[maxn][maxn][maxx];

ll count_tastiness( ll x, vector<ll> a ){
	for( int i = 0; i < (int)a.size(); i++ ){
		if( a[i] >= x ){
			if( i == (int)a.size() - 1 ) a.push_back(0LL);
			ll aux = (a[i] - x)/2;
			a[i + 1] += aux;
			a[i] -= 2*aux;
		}
	}
	a.push_back(0);
	int n = a.size();
	if( x > 1 ) return 0;

	reverse( a.begin(), a.end() );
	ll resp = 1;
	for( int l = 0, r = 0; l < n; l = r ){
		r = l + 1;
		while( r < n && a[r] == 1 ) r++;
		if( r == n || a[r] == 0 ) resp *= (1LL<<(r - l - 1));
		else resp *= (1LL + (1LL<<(r - l)));

	}

	return resp;




	for( int i = 0; i < n; i++ ) for( int j = 0; j < n; j++ ) for( int k = 0; k < x + 10; k++ ) dp[i][j][k] = -1;


	int max_shift = 0;
	for( int i = 0; i <= n; i++ ){
		if( (x<<i) > inf ) break;
		max_shift = i;
	}

	function<ll( int, int, ll, ll )> solve = [&]( int i, int j, ll remain, ll num ){
		if( i < 0 ) return 1LL;
		if( dp[i][j][remain] != -1 ) return dp[i][j][remain];
		ll &resp = dp[i][j][remain];
		resp = solve( i - 1, j, remain, num);
		if( i > max_shift ) return resp;
		ll goal = (x<<i);
		if( j > i ){ j = i; remain = a[i]; }
		if( (remain<<j) >= goal ){
			ll qtd = (goal>>j);
			remain -= qtd;
			ll aux = solve( i - 1, j, remain, num + (1LL<<i) );

			// cout << "1 " << resp + aux << endl;
			return resp + aux;
		}
		goal -= (remain<<j);
		j--;
		while( j >= 0 ){
			if( (a[j]<<j) >= goal ){
				ll qtd = (goal>>j);
				remain = a[j] - qtd;
				ll aux = solve( i - 1, j, remain, num + (1LL<<i) );
				// cout << "2 " << resp + aux << endl;
				return resp + aux;
			}
			goal -= (a[j]<<j);
			j--;
		}
		// cout << "3 " << resp << endl;
		return resp;
	};

	return solve( n - 1, n - 1, a[n - 1], 0 );
}
#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...