답안 #622816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
622816 2022-08-04T15:23:00 Z erekle 비스킷 담기 (IOI20_biscuits) C++17
9 / 100
1000 ms 340 KB
#include "biscuits.h"
#include <bits/stdc++.h>

using namespace std;

const int MX = 60;

long long count_tastiness(long long x, vector<long long> a) {
	int k = a.size();
	k = MX;
	while (a.size() < k) a.push_back(0);
	long long maxSum = 0;
	for (int i = 0; i < k; ++i) {
		maxSum += (1LL << i) * a[i];
	}

	auto possible = [&k, &a, &maxSum, &x](const bitset<MX> &y) {
		long long need = 0; // as a multiple of current power of two
		for (int i = k-1; i >= 0; --i) {
			if (y[i]) need += x;
			long long use = min(need, a[i]);
			need -= use;
			need <<= 1;
			if (need > maxSum) return false;
		}
		return !need;
	};

	bitset<MX> y = 0;
	long long ans = 1;
	bool foundNext = true;
	while (foundNext) {
		foundNext = false;
		bitset<MX> z = y;
		// find next highest y-value that works
		for (int i = 0; i < k; ++i) {
			if (y[i]) {z[i] = 0; continue;}
			// change a 0 into a 1, and set all smaller bits to 0
			z[i] = 1;
			if (possible(z)) {
				++ans, y = z;
				foundNext = true;
				break;
			}
			z[i] = 0;
		}
	}
	return ans;
}

Compilation message

biscuits.cpp: In function 'long long int count_tastiness(long long int, std::vector<long long int>)':
biscuits.cpp:11:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   11 |  while (a.size() < k) a.push_back(0);
      |         ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 21 ms 212 KB Output is correct
5 Correct 5 ms 212 KB Output is correct
6 Correct 53 ms 272 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 53 ms 212 KB Output is correct
9 Correct 8 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 22 ms 300 KB Output is correct
13 Correct 11 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 300 KB Output is correct
2 Execution timed out 1086 ms 212 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1093 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 21 ms 212 KB Output is correct
5 Correct 5 ms 212 KB Output is correct
6 Correct 53 ms 272 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 53 ms 212 KB Output is correct
9 Correct 8 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 22 ms 300 KB Output is correct
13 Correct 11 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 14 ms 300 KB Output is correct
16 Execution timed out 1086 ms 212 KB Time limit exceeded
17 Halted 0 ms 0 KB -