AT_abc473_g.Wipeout
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are N cards arranged face down in a row, each with one of the integers 1,2,…,N written on its face.
The order of these cards is determined uniformly at random from the N! possible orders.
You know that there is exactly one card with each of the integers 1,2,…,N written on its face and that the cards were arranged uniformly at random, but you have no other information about the integers written on the faces of the cards.
You play the following game.
- Initially, let the variable x=1.
- As long as x≤N, repeat the following operation. One operation consists of the following three steps.
- Specify one card and turn it face up.
- If the integer written on the card is x, eat that card and add 1 to x.
- Otherwise, turn that card face down. You can permanently remember the integer written on that card.
You always act so that the expected value of the total number of operations until all cards have been eaten is minimized.
In this case, what is the probability that the total number of operations is K? Find it modulo 998244353.
Definition of probability modulo 998244353
It can be proved that the sought probability is always a rational number. Also, under the constraints of this problem, it can be proved that when the rational number to be found is expressed as an irreducible fraction QP, we have Q≡0(mod998244353). Therefore, there is a unique integer R satisfying R×Q≡P(mod998244353),0≤R<998244353. Output this R.
有 N 张卡片,面朝下排成一行,每张卡片正面写有一个 1,2,…,N 中的整数。
这些卡片的排列顺序在全部 N! 种可能的顺序中均匀随机选取。
你已知:每张卡片正面恰好写有 1 至 N 中的一个整数(即所有整数各出现一次),且卡片排列是均匀随机的;除此之外,你对卡片正面所写的具体数字一无所知。
你参与如下游戏:
- 初始时,令变量 x=1。
- 当 x≤N 时,重复执行以下操作。每次操作包含以下三个步骤:
- 指定一张卡片,并将其翻至正面朝上;
- 若该卡片正面所写的整数为 x,则吃掉该卡片,并将 x 增加 1;
- 否则,将该卡片翻回背面朝下;但你可以永久记住这张卡片正面所写的数字。
你始终采取最优策略,使得“直到所有卡片均被吃掉所需的总操作次数”的期望值最小。
在此前提下,求“总操作次数恰好为 K”的概率,并对 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 K
输入从标准输入中以如下格式给出:
N K
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
3 4
输出#1
499122177
输入#2
3 6
输出#2
0
输入#3
500000 777777
输出#3
251612105
说明/提示
Sample 1 Explanation:
For this input, N=3. Let us call the cards a,b,c in the order they are arranged.
Below is an example of your actions when acting so that the expected value of the total number of operations is minimized.
- First, turn a face up.
- If 1 is written on a, eat that card.
- Next, turn b face up.
- If 2 is written on b, eat that card.
- Next, turn c face up; since 3 is necessarily written on it, eat it. In this case, you eat all cards in three operations, and the probability of this happening is 1/6.
- If 3 is written on b, turn that card face down.
- Next, turn c face up; since 2 is necessarily written on it, eat it. After that, turn b face up and eat it. In this case, you eat all cards in four operations, and the probability of this happening is 1/6.
- If 2 is written on a, turn that card face down.
- Next, turn b face up.
- If 1 is written on b, eat that card.
- Next, turn a face up and eat it. Next, turn c face up; since 3 is necessarily written on it, eat it. In this case, you eat all cards in four operations, and the probability of this happening is 1/6.
- If 3 is written on b, turn that card face down.
- At this point, it has become clear which integer is written on every one of the cards. So, perform three operations and eat all the cards in order of their numbers. In this case, you eat all cards in five operations, and the probability of this happening is 1/6.
- If 3 is written on a, turn that card face down.
- Next, turn b face up.
- If 1 is written on b, eat that card.
- Next, turn c face up; since 2 is necessarily written on it, eat it. After that, turn a face up and eat it. In this case, you eat all cards in four operations, and the probability of this happening is 1/6.
- If 2 is written on b, turn that card face down.
- At this point, it has become clear which integer is written on every one of the cards. So, perform three operations and eat all the cards in order of their numbers. In this case, you eat all cards in five operations, and the probability of this happening is 1/6.
Combining everything, the probability that the total number of operations is 3 is 1/6, the probability that it is 4 is 1/2, and the probability that it is 5 is 1/3.
For this sample, output 499122177, which represents 1/2 modulo 998244353.
Constraints
- All input values are integers.
- 1≤N≤5×105
- N≤K≤109
样例 1 解释:
对于该输入,N=3。我们将按排列顺序依次称这三张卡片为 a,b,c。
以下是为使总操作次数的期望值最小而采取的一种行动方案示例:
- 首先,将卡片 a 翻至正面朝上。
- 若 a 上写有数字 1,则吃掉该卡片。
- 接着,将卡片 b 翻至正面朝上。
- 若 b 上写有数字 2,则吃掉该卡片。
- 接着,将卡片 c 翻至正面朝上;由于此时 c 上必然写有数字 3,故吃掉它。此情形下,你共用 3 次操作吃掉全部卡片,发生的概率为 1/6。
- 若 b 上写有数字 3,则将该卡片翻至反面朝下。
- 接着,将卡片 c 翻至正面朝上;由于此时 c 上必然写有数字 2,故吃掉它。之后,再将 b 翻至正面朝上并吃掉。此情形下,你共用 4 次操作吃掉全部卡片,发生的概率为 1/6。
- 若 a 上写有数字 2,则将该卡片翻至反面朝下。
- 接着,将卡片 b 翻至正面朝上。
- 若 b 上写有数字 1,则吃掉该卡片。
- 接着,将卡片 a 翻至正面朝上并吃掉。然后,将卡片 c 翻至正面朝上;由于此时 c 上必然写有数字 3,故吃掉它。此情形下,你共用 4 次操作吃掉全部卡片,发生的概率为 1/6。
- 若 b 上写有数字 3,则将该卡片翻至反面朝下。
- 此时,每张卡片上所写的整数均已确定。因此,执行三次操作,按数字大小顺序依次吃掉所有卡片。此情形下,你共用 5 次操作吃掉全部卡片,发生的概率为 1/6。
- 若 a 上写有数字 3,则将该卡片翻至反面朝下。
- 接着,将卡片 b 翻至正面朝上。
- 若 b 上写有数字 1,则吃掉该卡片。
- 接着,将卡片 c 翻至正面朝上;由于此时 c 上必然写有数字 2,故吃掉它。之后,再将 a 翻至正面朝上并吃掉。此情形下,你共用 4 次操作吃掉全部卡片,发生的概率为 1/6。
- 若 b 上写有数字 2,则将该卡片翻至反面朝下。
- 此时,每张卡片上所写的整数均已确定。因此,执行三次操作,按数字大小顺序依次吃掉所有卡片。此情形下,你共用 5 次操作吃掉全部卡片,发生的概率为 1/6。
综上,总操作次数为 3 的概率为 1/6,为 4 的概率为 1/2,为 5 的概率为 1/3。
对于本样例,输出 499122177,即 1/2 对 998244353 取模的结果。
约束条件
- 所有输入值均为整数。
- 1≤N≤5×105
- N≤K≤109
输入解题思路,AI测评打分。不知道怎么写?