#abc331g. G - Collect Them All

G - Collect Them All

Score : 625625 points

问题描述

在一个盒子里有 NN 张卡片。每张卡片上都写有一个整数,这个整数介于 11MM(包含)之间。对于每个 i=1,,Mi=1,\ldots,M,有 CiC_i 张卡片上写着数字 ii

从一本空白笔记本开始,你重复以下操作:

  • 随机从盒子里抽出一张卡片。将卡片上的整数记在笔记本上,然后将卡片放回盒子。

求出执行该操作直至笔记本中至少记录过一次从 11MM 的所有整数的期望次数,结果对 998244353998244353 取模。

如何求解模 998244353998244353 下的期望值 本问题所求的期望值可以被证明始终是一个有理数。此外,本题的约束条件保证了当期望值表示为不可约分数 yx\frac yx 时,分母 xx 不会是 998244353998244353 的倍数。因此,存在一个唯一的 0z<9982443530\leq z\lt998244353,使得 yxz(mod998244353)y\equiv xz\pmod{998244353}。请输出这个 zz

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN cards in a box. Each card has an integer written on it, which is between 11 and MM, inclusive. For each i=1,,Mi=1,\ldots,M, there are CiC_i cards with the number ii written on them.

Starting with an empty notebook, you repeat the following operation:

  • Randomly draw one card from the box. Write the integer on the card in the notebook, then return the card to the box.

Find the expected value, modulo 998244353998244353, of the number of times the operation is performed until the notebook has all integers from 11 to MM written at least once.

How to find an expected value modulo 998244353998244353 The expected value sought in this problem can be proven to always be a rational number. Furthermore, the constraints of this problem guarantee that when the expected value is expressed as an irreducible fraction yx\frac yx, the denominator xx is not divisible by 998244353998244353. Then, there is a unique 0z<9982443530\leq z\lt998244353 such that yxz(mod998244353)y\equiv xz\pmod{998244353}. Print this zz.

Constraints

  • 1MN2×1051 \leq M \leq N \leq 2\times 10^5
  • 1Ci1 \leq C_i
  • i=1MCi=N\sum_{i=1}^{M}C_i=N
  • All input values are integers.

Input

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

NN MM

C1C_1 \ldots CMC_M

Output

Print the answer.

Sample Input 1

2 2
1 1

Sample Output 1

3

The series of operations may proceed as follows:

  • You draw a card with 11 written on it. The notebook now has one 11 written in it.
  • You again draw a card with 11 written on it. The notebook now has two 11s written in it.
  • You draw a card with 22 written on it. The notebook now has two 11s and one 22 written in it.

The sought expected value is $2\times\frac{1}{2}+3\times\frac{1}{4}+4\times\frac{1}{8}+\ldots=3$.

Sample Input 2

5 2
4 1

Sample Output 2

748683270

The expected value is 214\frac{21}{4}, whose representation modulo 998244353998244353 is 748683270748683270.

Sample Input 3

50 50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Sample Output 3

244742906

The expected value is $\frac{13943237577224054960759}{61980890084919934128}$.

Sample Input 4

74070 15
1 2 3 11 22 33 111 222 333 1111 2222 3333 11111 22222 33333

Sample Output 4

918012973

update @ 2024/3/10 01:16:32