AT_abc464_f.Random Vault Heist

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kowasugi Bank has NN safes. Safe ii contains AiA_i yen.

One day, a robber entered the bank. The robber repeats the following operation until the total amount stolen reaches at least XX yen:

  • Choose one safe uniformly at random from the safes not yet opened, open it, and steal all the money inside.

Find the expected value, modulo 998244353998244353, of the total amount stolen by the robber.

Definition of expected value modulo 998244353998244353

It can be proved that the expected value sought is always a rational number. Moreover, under the constraints of this problem, it can also be proved that when this value is expressed as an irreducible fraction PQ\frac{P}{Q}, it satisfies Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}. Therefore, there exists a unique integer RR satisfying R×Q≡P(mod998244353),0≤R<998244353R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353. Find this RR.

小和杉银行有 NN 个保险箱。第 ii 个保险箱中存有 AiA_i 日元。

某日,一名劫匪闯入了该银行。劫匪重复执行以下操作,直到所盗取的总金额至少达到 XX 日元:

  • 在尚未打开的保险箱中均匀随机选择一个保险箱,将其打开,并盗走其中全部的钱款。

求劫匪所盗取的总金额的期望值(对 998244353998244353 取模)。

关于“对 998244353998244353 取模的期望值”的定义:

可以证明,本题所求的期望值恒为有理数。此外,在本题的约束条件下还可证明:若将该有理数表示为既约分数 PQ\frac{P}{Q},则必有 Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}。因此,存在唯一的整数 RR 满足

R×Q≡P(mod998244353),0≤R<998244353.R \times Q \equiv P \pmod{998244353},\quad 0 \leq R < 998244353.

请输出该 RR。

输入格式

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

NN XX
A1A_1 A2A_2 …\ldots ANA_N

输入从标准输入中按以下格式给出:

NN XX
A1A_1 A2A_2 …\ldots ANA_N

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    2 5
    3 10

    输出#1

    499122188
  • 输入#2

    3 2
    1 1 1

    输出#2

    2
  • 输入#3

    11 60
    2 3 5 7 11 13 17 19 23 29 31

    输出#3

    525950964

说明/提示

Sample 1 Explanation:
There are two choices for the first safe to open.
If safe 11 is opened first, the robber also opens safe 22, so the total amount stolen is 1313 yen.
If safe 22 is opened first, the total already reaches at least XX yen at that point, so the total amount stolen is 1010 yen.
Thus, the expected value is 13+102=232\frac{13 + 10}{2} = \frac{23}{2}.

Sample 2 Explanation:
Regardless of the order in which they are opened, the total amount stolen when two safes have been opened is 22 yen. Thus, the expected value is 22.

Constraints

  • 1≤N≤401 \le N \le 40
  • 1≤Ai≤10161 \le A_i \le 10^{16}
  • 1≤X≤∑i=1NAi1 \le X \le \sum_{i=1}^{N} A_i
  • All input values are integers.

样例 1 解释:
打开第一个保险箱有两种选择。
若首先打开保险箱 11,劫匪还会接着打开保险箱 22,因此总共窃取的金额为 1313 日元。
若首先打开保险箱 22,此时总金额已至少达到 XX 日元,因此总共窃取的金额为 1010 日元。
因此,期望值为 13+102=232\frac{13 + 10}{2} = \frac{23}{2}。

样例 2 解释:
无论以何种顺序打开保险箱,当打开两个保险箱时,总共窃取的金额恒为 22 日元。因此,期望值为 22。

限制条件

  • 1≤N≤401 \le N \le 40
  • 1≤Ai≤10161 \le A_i \le 10^{16}
  • 1≤X≤∑i=1NAi1 \le X \le \sum_{i=1}^{N} A_i
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页