제출 #467069

#제출 시각아이디문제언어결과실행 시간메모리
467069armand비스킷 담기 (IOI20_biscuits)C++14
0 / 100
1 ms460 KiB
#include "biscuits.h"
#include <algorithm>
using namespace std;

int check_y(long long x, std::vector<long long> a, int y)
{
	int i;
	vector<int> b;
	i = 0;
	while (y) {
		b.push_back(y % 2);
		y = y >> 1;
	}
	i = b.size()-1;
	while (i) {
		if (a[i] < 0) {
			a[i - 1] += 2 * a[i];
			a[i] = 0;
		}
		if (b[i]) {
			if (a[i] < x)
				a[i - 1] -= 2 * (x - a[i]);
		}
		i--;
	}
	if(b[0])
		return a[0] >= x;
	return a[0] >= 0;
}

long long count_tastiness(long long x, std::vector<long long> a) 
{
	int res = 1;
	int k = a.size();
	long long total = 0;
	long long two = 1;
	for (int i = 0; i < k; i++) {
		total += two*a[i];
		two <<= 1;
	}
	for (int y = 1; y*x <= total; y++)
		res += check_y(x, a, y);
	return res;
}

#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...