AtCoder Regular Contest 217
C
Greedy Customers 2
AtCoder
⌀ 2173
原题
← BD →

Greedy Customers 2AI (CI翻译)

Problem Statement

AtCoder Store has $N$ items. The $i$-th item costs $A_i$ yen.

$N$ people visit the store one by one. Each person has $C$ yen and performs the following procedure.

  • Choose an integer $x$ uniformly at random between $1$ and $C$, inclusive, as the budget for shopping.
  • If there is an item remaining in the store that costs at most $x$ yen, purchase one of the most expensive ones among them. Otherwise, leave the store without purchasing anything.

As the owner of the store, you want to know how many items will be sold. For $k=0,1,2,\ldots,N$, find the probability, modulo $998244353$, that exactly $k$ items are sold in the end.

You are given $T$ test cases; solve each of them.

Definition of probability $\ \text{mod}\ 998244353$ It can be proved that the probabilities to be found are always rational numbers. Moreover, under the constraints of this problem, when each such rational number is expressed as an irreducible fraction $\displaystyle \frac{P}{Q}$, it can be proved that $Q \neq 0 \bmod 998244353$. Thus, there is a unique integer $R$ satisfying $R \times Q \equiv P \bmod 998244353, 0 \leq R \lt 998244353$. Find this $R$.

Constraints

  • $1\le T$
  • $1\le N$
  • The sum of $N$ over all test cases is at most $100$.
  • $1\le A_i \le C < 998244353$
  • All input values are integers.

Input

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

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

Each test case is given in the following format:

N C
A_1 A_2 \ldots A_N

Output

Output the answers for the test cases in order, separated by newlines.

For each test case, output the answers for $k=0,1,\ldots,N$ in order, separated by spaces.

{"titleZh":"贪心顾客 2","bodyZh":"## 题目描述\n\nAtCoder 商店有 $N$ 件商品。第 $i$ 件商品的价格为 $A_i$ 日元。\n\n有 $N$ 个人依次来到商店。每个人有 $C$ 日元,并执行以下流程。\n\n- 在 $1$ 到 $C$ 之间(包含两端)等概率随机选择一个整数 $x$,作为购物预算。\n- 如果商店中还有价格不超过 $x$ 日元的商品,则购买其中价格最高的一件。否则,不购买任何商品就离开商店。\n\n作为商店的店主,你想知道最终会卖出多少件商品。对于 $k=0,1,2,\ldots,N$,求最终恰好卖出 $k$ 件商品的概率,并对 $998244353$ 取模。\n\n给定 $T$ 组测试数据,请分别求解。\n\n概率对 $998244353$ 取模的定义 可以证明,所求概率始终是有理数。此外,在本题约束下,将每个有理数表示为最简分数 $\displaystyle \\frac{P}{Q}$ 时,可以证明 $Q \\neq 0 \\bmod 998244353$。因此,满足 $R \\times Q \\equiv P \\bmod 998244353, 0 \\leq R \\lt 998244353$ 的整数 $R$ 唯一存在。请求出这个 $R$。\n\n## 约束条件\n\n- $1\\le T$\n- $1\\le N$\n- 所有测试数据中的 $N$ 之和不超过 $100$。\n- $1\\le A_i \\le C < 998244353$\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入中按以下格式给出:\n\n\nT\n\\text{case}_1\n\\text{case}_2\n\\vdots\n\\text{case}_T\n`\n\n每组测试数据的格式如下:\n\n`\nN C\nA_1 A_2 \\ldots A_N\n\n\n## 输出格式\n\n按顺序输出各组测试数据的答案,每组之间用换行分隔。\n\n对于每组测试数据,按顺序输出 $k=0,1,\\ldots,N$ 时的答案,答案之间用空格分隔。"}AI (CI翻译)

样例

Input #1
4
2 3
1 3
3 17
9 9 8
5 2025
1 1 1 1 1
6 1000
544 105 450 715 479 992
Output #1
0 776412275 221832079
465698363 588015298 487439081 455335965
0 0 0 0 0 1
366062443 766314649 169448288 553531286 643499511 890090646 604030590
Consider the first test case. For example, the procedure for each person proceeds as follows. - Person $1$: Chooses $x=2$. The most expensive item that costs at most $2$ yen is the first item, so they purchase the first item. - Person $2$: Chooses $x=1$. There are no items costing at most $1$ yen, so they leave without purchasing anything. In this case, exactly one item is sold in the end. The probabilities that exactly $0,1,2$ items are sold are $\displaystyle 0, \frac49,\frac59$, respectively.
题目信息
题号
arc217_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。