#ABC473G. 翻牌消除 / Wipeout
翻牌消除 / Wipeout
Problem Statement
There are cards arranged face down in a row, each with one of the integers written on its face. The order of these cards is determined uniformly at random from the possible orders. You know that there is exactly one card with each of the integers 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 .
- As long as , 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 , eat that card and add to .
- 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 ? Find it modulo .
Definition of probability modulo
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 , we have . Therefore, there is a unique integer satisfying $R \times Q \equiv P \pmod{998244353}, 0 \leq R \lt 998244353$. Output this .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Output the answer.
3 4
499122177
For this input, . Let us call the cards 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 face up.
- If is written on , eat that card.
- Next, turn face up.
- If is written on , eat that card.
- Next, turn face up; since is necessarily written on it, eat it. In this case, you eat all cards in three operations, and the probability of this happening is .
- If is written on , turn that card face down.
- Next, turn face up; since is necessarily written on it, eat it. After that, turn face up and eat it. In this case, you eat all cards in four operations, and the probability of this happening is .
- If is written on , eat that card.
- Next, turn face up.
- If is written on , turn that card face down.
- Next, turn face up.
- If is written on , eat that card.
- Next, turn face up and eat it. Next, turn face up; since is necessarily written on it, eat it. In this case, you eat all cards in four operations, and the probability of this happening is .
- If is written on , 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 .
- If is written on , eat that card.
- Next, turn face up.
- If is written on , turn that card face down.
- Next, turn face up.
- If is written on , eat that card.
- Next, turn face up; since is necessarily written on it, eat it. After that, turn face up and eat it. In this case, you eat all cards in four operations, and the probability of this happening is .
- If is written on , 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 .
- If is written on , eat that card.
- Next, turn face up.
- If is written on , eat that card.
Combining everything, the probability that the total number of operations is is , the probability that it is is , and the probability that it is is . For this sample, output , which represents modulo .
3 6
0
500000 777777
251612105
- Source: AtCoder ABC 473 G
相关
在下列比赛中: