Submission #305844

#TimeUsernameProblemLanguageResultExecution timeMemory
305844ksun48Packing Biscuits (IOI20_biscuits)C++14
100 / 100
37 ms896 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i128 = __int128_t;

ll count_tastiness(ll x, vector<ll> a) {
	const i128 B = 60;
	vector<i128> A(B, 0);
	for(int i = 0; i < (int)a.size(); i++) A[i] = a[i];
	i128 X = x;
	vector<i128> psum(B+1, 0);
	for(int i = 0; i < B; i++){
		psum[i+1] = psum[i] + (A[i] << i);
	}
	vector<i128> cnt(B+1, 0);
	cnt[B] = 1;
	for(int i = B; i > 0; i--){
		i128 cmin = psum[i];
		i128 cmax = psum[i];
		for(int j = i-1; j >= 0; j--){
			if(cmin >= (X << j)) cmin -= (X << j);
			if(cmax >= psum[j]){
				if(cmax >= cmin){
					cnt[j] += cnt[i] * (1 + (cmax - max(cmin, psum[j])) / (X << j));
				}
				cmax -= (1 + (cmax - psum[j]) / (X << j)) * (X << j);
			}
		}
	}
	return (ll)cnt[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...