Submission #604930

#TimeUsernameProblemLanguageResultExecution timeMemory
604930gagik_2007Packing Biscuits (IOI20_biscuits)C++17
0 / 100
1088 ms1056 KiB
#include "biscuits.h"
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef ll itn;

#define ff first
#define ss second

ll n;
ll lg;
ll dp[100007][107];

ll count_tastiness(ll x, vector<ll> a) {
	n = a.size();
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i] * (1ll << i);
	}
	if (x == 1) {
		lg = min(sum, 100000ll);
		for (int i = 0; i <= lg; i++) {
			if (a[0] >= (1ll << i)) {
				dp[0][i] = 1;
			}
		}
		for (int i = 1; i < n; i++) {
			for (int j = 0; j <= lg; j++) {
				for (int tv = 0; tv <= min(a[i], j * 1ll); tv++) {
					int vek = j - tv;
					vek *= 2;
					if (vek <= lg) {
						dp[i][j] += dp[i - 1][vek];
					}
				}
			}
		}
		ll ans = 1;
		for (int i = 0; i < n; i++) {
			ans *= dp[i][1];
		}
		return ans;
	}
	sum /= x;
	ll ans = 1;
	for (int y = 1; y <= sum; y++) {
		vector<ll>c = a;
		bool ys = true;
		for (int i = 0; i < x; i++) {
			ll val = y;
			for (int j = n - 1; j >= 0; j--) {
				ll cnt = val / (1ll << j);
				ll v = min(cnt, c[j]);
				c[j] -= v;
				val -= v * (1ll << j);
			}
			if (val != 0) {
				ys = false;
				break;
			}
		}
		ans += ys;
	}
	return 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...