atcoder#ARC114E. [ARC114E] Paper Cutting 2
[ARC114E] Paper Cutting 2
Score : points
Problem Statement
We have a rectangular piece of paper divided into squares, where two of those squares are painted black and the rest are painted white. If we let denote the square at the -th row and -th column, the squares painted black are and .
Maroon will repeat the following operation to cut the piece of paper:
- Assume that we have squares remaining. There are horizontal lines and vertical lines that are parallel to the edges of the piece and pass the borders of the squares. He chooses one of these lines uniformly at random and cuts the piece into two along that line. Then,- if the two black squares are on the same piece, he throws away the other piece and continues the process;
- otherwise, he ends the process.
- if the two black squares are on the same piece, he throws away the other piece and continues the process;
- otherwise, he ends the process.
Find the expected value of the number of times Maroon cuts a piece of paper until he ends the process, modulo .
Notes
We can prove that the expected value in question is always a rational number. Additionally, under the constraints of this problem, we can also prove that if we express that value as an irreducible fraction , we have . Thus, there exists a unique integer such that $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$. Answer this .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Find the expected value of the number of times Maroon cuts a piece of paper until he ends the process, modulo .
2 3
2 2 1 1
332748119
In the first cut, the process will end with probability . For the remaining case with probability , the process will end in the second cut.
Thus, the expected number of cuts is .
1 5
1 2 1 3
332748120
2 1
2 1 1 1
1
The process will always end in the first cut.
10 10
3 4 5 6
831078040