#P5577. [CmdOI2019] 算力训练

[CmdOI2019] 算力训练

Description

The problem setter wrote down nn base-kk natural numbers on a slip of paper. Because he is lazy, these numbers will not have too many digits, and none of them exceeds mm digits.

To train computing power, each time he will randomly pick a subsequence (it is allowed to pick none), and then add all the chosen numbers together.

He also felt carrying was too troublesome, so he simply规定 that addition is done without carry.

After computing a few times, he suddenly wanted to know how many ways he can obtain each number, but he is too weak and cannot compute it. After thinking hard, he was suddenly pulled out of the dream by the wake-up bell.

He found this problem interesting, so he had to ask you, who can crush countless algebra problems with one hand, to help compute it.

Formal statement: For a sequence AA, define its weight W(A)W(A) as the sum of the elements in AA using base-kk addition without carry.

Given mm, kk, and a sequence SS of length nn. It is guaranteed that S[0,km)ZS\subseteq [0,k^m)∩Z.

For t=0,1,2,...,km1t=0,1,2,...,k^m-1, compute the value of:

$${\rm Ans}[t]=\sum\limits_{\text{R is a subsequence of S}}\big[W(R)=t\big]$$

Note: From the correct statement, we can infer that t=0km1Ans[t]=2n\sum\limits_{t=0}^{k^m-1}{\rm Ans}[t]=2^n.

Input Format

The first line contains three integers n,k,mn,k,m, with the meaning described in the statement.

The second line contains nn integers separated by spaces, representing the numbers on the slip of paper.

(Note: the numbers on the slip of paper are all base-kk numbers.)

Output Format

There are kmk^m lines. On the ii-th line, output the number of ways to obtain the number i1i-1. Output the answer modulo 998244353998244353.

3 5 1
1 2 3
2
2
1
2
1
5 6 1
1 1 4 5 1 4
8
7
4
2
4
7

Hint

Sample Explanation

For Sample #1, there are 23=82^3=8 ways to choose a subsequence:

  1. Choose nothing, the sum is 00.
  2. Choose 11, the sum is 11.
  3. Choose 22, the sum is 22.
  4. Choose 33, the sum is 33.
  5. Choose 1+21+2, the sum is 33.
  6. Choose 1+31+3, the sum is 44.
  7. Choose 2+32+3, the sum is 00 (since it is base 55, it should become 1010, but without carry it becomes only 00).
  8. Choose 1+2+31+2+3, the sum is 11.

In summary, the numbers of ways to obtain 0,1,2,3,4 are 2,2,1,2,1, respectively.

Constraints and Conventions

Test Point ID n k m Total Score
#1 2020 55 44 55
#2 10001000
#3~4 10610^6 55 1010
#5 66
#6~7 77 2020
#8 2020 66 44 55
#9 10001000
#10~11 10610^6 1010
#12~14 66 3030

Translated by ChatGPT 5