E - Kth Number Editorial /

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 500500

問題文

00 以上 MM 以下の整数からなる長さ NN の数列 A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N) があります。

今からすぬけくんが以下の操作 1, 2 を順に行います。

  1. Ai=0A_i=0 を満たすそれぞれの ii について、11 以上 MM 以下の整数を独立かつ一様ランダムに選び、AiA_i をその整数で置き換える。
  2. AA を昇順に並び替える。

すぬけくんが操作 1, 2 を行ったあとの AKA_K の期待値を mod 998244353\text{mod } 998244353 で出力してください。

「期待値を mod 998244353\text{mod } 998244353 で出力」とは 求める期待値は必ず有理数となることが証明できます。 またこの問題の制約下では、その値を互いに素な 22 つの整数 PP, QQ を用いて PQ\frac{P}{Q} と表したとき、 R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} かつ 0R<9982443530 \leq R \lt 998244353 を満たす整数 RR がただ 11 つ存在することが証明できます。この RR を出力してください。

制約

  • 1KN20001\leq K \leq N \leq 2000
  • 1M20001\leq M \leq 2000
  • 0AiM0\leq A_i \leq M
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

NN MM KK
A1A_1 A2A_2 \dots ANA_N

出力

すぬけくんが操作 1, 2 を行ったあとの AKA_K の期待値を mod 998244353\text{mod } 998244353 で出力せよ。


入力例 1Copy

Copy
3 5 2
2 0 4

出力例 1Copy

Copy
3

すぬけくんは操作 1 において A2A_211 以上 55 以下の整数で置き換えます。この整数を xx とすると、

  • x=1,2x=1,2 のとき、すぬけくんが操作 1, 2 を行ったあと A2=2A_2=2 です。
  • x=3x=3 のとき、すぬけくんが操作 1, 2 を行ったあと A2=3A_2=3 です。
  • x=4,5x=4,5 のとき、すぬけくんが操作 1, 2 を行ったあと A2=4A_2=4 です。

よって、A2A_2 の期待値は 2+2+3+4+45=3\frac{2+2+3+4+4}{5}=3 です。


入力例 2Copy

Copy
2 3 1
0 0

出力例 2Copy

Copy
221832080

期待値は 149\frac{14}{9} です。


入力例 3Copy

Copy
10 20 7
6 5 0 2 0 0 0 15 0 0

出力例 3Copy

Copy
617586310

Score : 500500 points

Problem Statement

We have a sequence of length NN consisting of integers between 00 and MM, inclusive: A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N).

Snuke will perform the following operations 1 and 2 in order.

  1. For each ii such that Ai=0A_i=0, independently choose a uniform random integer between 11 and MM, inclusive, and replace AiA_i with that integer.
  2. Sort AA in ascending order.

Print the expected value of AKA_K after the two operations, modulo 998244353998244353.

How to print a number modulo 998244353998244353? It can be proved that the sought expected value is always rational. Additionally, under the Constraints of this problem, when that value is represented as PQ\frac{P}{Q} using two coprime integers PP and QQ, it can be proved that there is a unique integer RR such that R×QP(mod998244353)R \times Q \equiv P\pmod{998244353} and 0R<9982443530 \leq R \lt 998244353. Print this RR.

Constraints

  • 1KN20001\leq K \leq N \leq 2000
  • 1M20001\leq M \leq 2000
  • 0AiM0\leq A_i \leq M
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM KK
A1A_1 A2A_2 \dots ANA_N

Output

Print the expected value of AKA_K after the two operations, modulo 998244353998244353.


Sample Input 1Copy

Copy
3 5 2
2 0 4

Sample Output 1Copy

Copy
3

In the operation 1, Snuke will replace A2A_2 with an integer between 11 and 55. Let xx be this integer.

  • If x=1x=1 or 22, we will have A2=2A_2=2 after the two operations.
  • If x=3x=3, we will have A2=3A_2=3 after the two operations.
  • If x=4x=4 or 55, we will have A2=4A_2=4 after the two operations.

Thus, the expected value of A2A_2 is 2+2+3+4+45=3\frac{2+2+3+4+4}{5}=3.


Sample Input 2Copy

Copy
2 3 1
0 0

Sample Output 2Copy

Copy
221832080

The expected value is 149\frac{14}{9}.


Sample Input 3Copy

Copy
10 20 7
6 5 0 2 0 0 0 15 0 0

Sample Output 3Copy

Copy
617586310


2025-04-29 (Tue)
02:55:36 +00:00