#P6836. [IOI 2020] 装饼干

    ID: 7745 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2020IOI交互题Special Judge

[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 xx participants, and she plans to give each participant a bag of biscuits. There are kk different types of biscuits, numbered from 00 to k1k-1. Each biscuit of type ii (0ik1)(0 \le i \le k-1) has a tastiness value of 2i2^i. In Aunt Khong’s food storage, there are a[i]a[i] (possibly 00) biscuits of type ii.

For each biscuit type, Aunt Khong may put 00 or more biscuits of that type into each bag. Across all bags, the total number of type ii biscuits used must not exceed a[i]a[i]. 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 yy exist such that she can pack xx bags of biscuits and the total tastiness of every bag is exactly yy.

Implementation Details

You need to implement the following function:

long long count_tastiness(long long x, std::vector<long long> a)
  • xx: the number of biscuit bags to pack.
  • aa: an array of length kk. For 0ik10 \le i \le k-1, a[i]a[i] is the number of type ii biscuits in the food storage.
  • This function should return the number of distinct values of yy such that Aunt Khong can pack xx bags and every bag has total tastiness yy.
  • This function will be called qq times (for allowed values of qq, 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 33 bags, and there are 33 biscuit types in the food storage in total:

  • 55 biscuits of type 00, each with tastiness 11,
  • 22 biscuits of type 11, each with tastiness 22,
  • 11 biscuit of type 22, with tastiness 44.

The possible values of yy are [0,1,2,3,4][0,1,2,3,4]. For example, to pack 33 bags each with total tastiness 33, Aunt Khong can pack them like this:

  • one bag contains 33 biscuits of type 00, and
  • two bags each contain one type 00 biscuit and one type 11 biscuit.

Since there are 55 possible values of yy in total, the function should return 55.

Example 2

Consider the following call:

count_tastiness(2, [2, 1, 2])

This means Aunt Khong wants to pack 22 bags, and there are 33 biscuit types in the food storage in total:

  • 22 biscuits of type 00, each with tastiness 11,
  • 11 biscuit of type 11, with tastiness 22,
  • 22 biscuits of type 22, each with tastiness 44.

The possible values of yy are [0,1,2,4,5,6][0,1,2,4,5,6]. Since there are 66 possible values of yy in total, the function should return 66.

Constraints

  • 1k601 \le k \le 60.
  • 1q10001 \le q \le 1000.
  • 1x10181 \le x \le 10^{18}.
  • 0a[i]10180 \le a[i] \le 10^{18} (for all 0ik10 \le i \le k-1).
  • For each call to count_tastiness, the total sum of tastiness values of all biscuits in the food storage does not exceed 101810^{18}.

Subtasks

  1. (9 points) q10q \le 10, and for each call to count_tastiness, the total sum of tastiness values of all biscuits in the food storage does not exceed 10510^5.
  2. (12 points) x=1,q10x = 1, q \le 10.
  3. (21 points) x104,q10x \le 10^4, q \le 10.
  4. (35 points) For each call to count_tastiness, the correct return value does not exceed 2×1052 \times 10^5.
  5. (23 points) No additional constraints.

Example Grader

The example grader will read input data in the following format. The first line contains an integer qq. Then there are qq pairs of two lines, each describing one scenario in the format below:

Line 11: k xk\ x
Line 22: a[0] a[1]  a[k1]a[0]\ a[1]\ \ldots\ a[k-1]

The output format of the example grader is:

Line ii (1iq)(1 \le i \le q): the return value of count_tastiness for the ii-th scenario in the input data.

Translated by ChatGPT 5