AT_abc464_f.Random Vault Heist
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Kowasugi Bank has N safes. Safe i contains Ai yen.
One day, a robber entered the bank. The robber repeats the following operation until the total amount stolen reaches at least X 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 998244353, of the total amount stolen by the robber.
Definition of expected value modulo 998244353
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 QP, it satisfies Q≡0(mod998244353). Therefore, there exists a unique integer R satisfying R×Q≡P(mod998244353),0≤R<998244353. Find this R.
小和杉银行有 N 个保险箱。第 i 个保险箱中存有 Ai 日元。
某日,一名劫匪闯入了该银行。劫匪重复执行以下操作,直到所盗取的总金额至少达到 X 日元:
- 在尚未打开的保险箱中均匀随机选择一个保险箱,将其打开,并盗走其中全部的钱款。
求劫匪所盗取的总金额的期望值(对 998244353 取模)。
关于“对 998244353 取模的期望值”的定义:
可以证明,本题所求的期望值恒为有理数。此外,在本题的约束条件下还可证明:若将该有理数表示为既约分数 QP,则必有 Q≡0(mod998244353)。因此,存在唯一的整数 R 满足
R×Q≡P(mod998244353),0≤R<998244353.
请输出该 R。
输入格式
The input is given from Standard Input in the following format:
N X
A1 A2 … AN
输入从标准输入中按以下格式给出:
N X
A1 A2 … AN
输出格式
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 1 is opened first, the robber also opens safe 2, so the total amount stolen is 13 yen.
If safe 2 is opened first, the total already reaches at least X yen at that point, so the total amount stolen is 10 yen.
Thus, the expected value is 213+10=223.
Sample 2 Explanation:
Regardless of the order in which they are opened, the total amount stolen when two safes have been opened is 2 yen. Thus, the expected value is 2.
Constraints
- 1≤N≤40
- 1≤Ai≤1016
- 1≤X≤∑i=1NAi
- All input values are integers.
样例 1 解释:
打开第一个保险箱有两种选择。
若首先打开保险箱 1,劫匪还会接着打开保险箱 2,因此总共窃取的金额为 13 日元。
若首先打开保险箱 2,此时总金额已至少达到 X 日元,因此总共窃取的金额为 10 日元。
因此,期望值为 213+10=223。
样例 2 解释:
无论以何种顺序打开保险箱,当打开两个保险箱时,总共窃取的金额恒为 2 日元。因此,期望值为 2。
限制条件
- 1≤N≤40
- 1≤Ai≤1016
- 1≤X≤∑i=1NAi
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?