Submission #418525

#TimeUsernameProblemLanguageResultExecution timeMemory
418525oolimryPacking Biscuits (IOI20_biscuits)C++17
0 / 100
1137 ms810412 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
typedef long long lint;
typedef pair<lint,lint> ii;

unordered_map<lint,lint> memo;
lint S[65];

lint dp(lint n){ ///number of good things <n
	if(n < 0) return 0;
	if(n == 1) return 1;
	if(memo.find(n) != memo.end()) return memo[n];
	
	lint a = 60;
	while(((1LL<<a)&(n-1))==0) a--;
	
	lint A = (1LL<<a);
	lint B = min(n,S[a]+1) - A;
	
	lint res = dp(A)+dp(B);
	return memo[n] = res;
}

lint count_tastiness(lint x, vector<lint> a){
	for(lint i = 0;i < 60;i++) S[i] = 0;
	for(lint i = 0;i < sz(a);i++) S[i] += (a[i]<<i);
	for(lint i = 1;i < 60;i++) S[i] += S[i-1];
	for(lint i = 0;i < 60;i++) S[i] /= x;
	
	memo.clear();
	return dp(1LL<<60LL);
}
#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...