Submission #433110

#TimeUsernameProblemLanguageResultExecution timeMemory
433110peuchPacking Biscuits (IOI20_biscuits)C++17
21 / 100
1099 ms63216 KiB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;

vector<map<long long, long long> > dp;
vector<long long> v(60);
long long X;

long long getDP(int bit, long long cnt){
	cnt += v[bit];
	if(bit == 60) return 1;
	if(dp[bit][cnt] != 0) return dp[bit][cnt];
	dp[bit][cnt] = getDP(bit + 1, cnt / 2);
	if(cnt >= X) dp[bit][cnt] += getDP(bit + 1, (cnt - X) / 2);
	return dp[bit][cnt];
}

long long sub1(long long x, vector<long long> a){
	long long ini = 0;
	long long ans = 1;
	for(ini = 0; ini < 60;){
		long long fim = ini;
		long long sobra = 0;
		long long num = 0;
		long long cnt = 0;
		while(fim < 60){
			long long val = 0;
			if(fim < a.size()) val = a[fim];
			long long tot = val + sobra;
			sobra = tot / 2;
			if(tot % 2 == 1) num |= (1LL << cnt);
			fim++;
			cnt++;
			if(sobra == 0) break;
		}
		ans *= num + 1;
		ini = fim;
	}
	return ans;
}

long long count_tastiness(long long x, vector<long long> a) {
	if(x == 1) return sub1(x, a);
	X = x;
	v = vector<long long> (60, 0);
	dp = vector<map<long long, long long> > (60);
	for(int i = 0; i < a.size(); i++)
		v[i] = a[i];
	return getDP(0, 0);
}

Compilation message (stderr)

biscuits.cpp: In function 'long long int sub1(long long int, std::vector<long long int>)':
biscuits.cpp:28:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    if(fim < a.size()) val = a[fim];
      |       ~~~~^~~~~~~~~~
biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i = 0; i < a.size(); i++)
      |                 ~~^~~~~~~~~~
#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...