#P6836. [IOI 2020] 装饼干
[IOI 2020] 装饼干
Background
Note: This problem only supports submissions in C++ and you should not use C++14 (GCC 9).
You do not need to add the following in your code:
#include "biscuits.h"
Problem Description
Aunt Khong is organizing a contest with participants, and she plans to give each participant a bag of biscuits. There are different types of biscuits, numbered from to . Each biscuit of type has a tastiness value of . In Aunt Khong’s food storage, there are (possibly ) biscuits of type .
For each biscuit type, Aunt Khong may put or more biscuits of that type into each bag. Across all bags, the total number of type biscuits used must not exceed . The sum of tastiness values of all biscuits in a bag is called the total tastiness of that bag.
Please help Aunt Khong compute how many different values of exist such that she can pack bags of biscuits and the total tastiness of every bag is exactly .
Implementation Details
You need to implement the following function:
long long count_tastiness(long long x, std::vector<long long> a)
- : the number of biscuit bags to pack.
- : an array of length . For , is the number of type biscuits in the food storage.
- This function should return the number of distinct values of such that Aunt Khong can pack bags and every bag has total tastiness .
- This function will be called times (for allowed values of , see Constraints and Subtasks). Each call should be considered an independent scenario.
Input Format
See Implementation Details.
Output Format
See Implementation Details.
Hint
Sample Explanation
Example 1
Consider the following call:
count_tastiness(3, [5, 2, 1])
This means Aunt Khong wants to pack bags, and there are biscuit types in the food storage in total:
- biscuits of type , each with tastiness ,
- biscuits of type , each with tastiness ,
- biscuit of type , with tastiness .
The possible values of are . For example, to pack bags each with total tastiness , Aunt Khong can pack them like this:
- one bag contains biscuits of type , and
- two bags each contain one type biscuit and one type biscuit.
Since there are possible values of in total, the function should return .

Example 2
Consider the following call:
count_tastiness(2, [2, 1, 2])
This means Aunt Khong wants to pack bags, and there are biscuit types in the food storage in total:
- biscuits of type , each with tastiness ,
- biscuit of type , with tastiness ,
- biscuits of type , each with tastiness .
The possible values of are . Since there are possible values of in total, the function should return .
Constraints
- .
- .
- .
- (for all ).
- For each call to
count_tastiness, the total sum of tastiness values of all biscuits in the food storage does not exceed .
Subtasks
- (9 points) , and for each call to
count_tastiness, the total sum of tastiness values of all biscuits in the food storage does not exceed . - (12 points) .
- (21 points) .
- (35 points) For each call to
count_tastiness, the correct return value does not exceed . - (23 points) No additional constraints.
Example Grader
The example grader will read input data in the following format. The first line contains an integer . Then there are pairs of two lines, each describing one scenario in the format below:
Line :
Line :
The output format of the example grader is:
Line : the return value of count_tastiness for the -th scenario in the input data.
Translated by ChatGPT 5