No.2230 Good Omen of White Lotus
タグ : / 解いたユーザー数 83
作問者 : 👑
akakimidori
👑
hamamu
Problem Statement
There is a grid with $H$ rows and $W$ columns, and the cell at row $i$ and column $j$ is denoted by cell $(i,j)$. Initially, you are at cell $(1,1)$.
You aim for cell $(H,W)$ by repeatedly moving from cell $(i,j)$ to cell $(i+1,j)$ or cell $(i,j+1)$. However, you cannot make a move that takes you outside the grid.
Good news is handed down at $N$ cells in this grid, and the $k$-th piece of good news is handed down at cell $(x_k, y_k)$.
Now, at every cell except cell $(1,1)$ and cell $(H,W)$, a white lotus flower blooms with a certain probability. The probability that a white lotus flower blooms at each cell is $\frac{2}{P}$ if good news is handed down at that cell, and $\frac{1}{P}$ otherwise (whether a white lotus flower blooms is determined independently for each cell). You can see a white lotus flower only when you are at the same cell as the one where it is blooming. Also, you cannot know whether a white lotus flower is blooming at any cell other than the one you are currently at.
You want to maximize the probability of seeing a white lotus flower at least once by the time you have moved from cell $(1,1)$ to cell $(H,W)$. Find the probability that you can see a white lotus flower when you use a way of moving that maximizes this probability, in $\bmod 998244353$ as described in the notes below.
Notes
It can be proved that the value to be found is a rational number. Also, under the constraints of this problem, it can be proved that when the value is expressed as $\frac{Y}{X}$ using $2$ coprime positive integers $X,Y$, there exists exactly one integer $Z$ in the range $0 \leq Z < 998244353$ such that $XZ \equiv Y \pmod{998244353}$. Output this $Z$.
Constraints
- All input values are integers.
- $2 \leq H,W \leq 2 \times 10^5$
- $0 \leq N \leq \min(HW - 2, 2 \times 10^5)$
- $2 \leq P < 998244353$
- $1 \leq x_k \leq H$
- $1 \leq y_k \leq W$
- $(x_k, y_k) \neq (1,1)$
- $(x_k, y_k) \neq (H,W)$
- $(x_k, y_k) \neq (x_l, y_l) (k \neq l)$
Input
The input is given from Standard Input in the following format.
$H$ $W$ $N$ $P$ $x_1$ $y_1$ $x_2$ $y_2$ $\vdots$ $x_N$ $y_N$
Output
Output the probability that you can see a white lotus flower at least once, in $\bmod 998244353$ as described in the notes.
Sample
Sample 1
Input
3 4 3 3 1 2 2 1 3 3
Output
690144245
For example, the following way of moving is optimal.
- Move as $(1,1) \rightarrow (1,2) \rightarrow (1,3) \rightarrow (2,3) \rightarrow (3,3) \rightarrow (3,4)$.
In this case, the probability of seeing a white lotus flower is $\frac{77}{81}$. Since $81 \times 690144245 \equiv 77 \pmod{998244353}$ holds, output $690144245$.
Sample 2
Input
2 2 1 2 1 2
Output
1
If you pass through cell $(1,2)$, you can always see a white lotus flower.
Sample 3
Input
12 15 8 2009 1 4 3 1 2 4 2 5 5 2 7 3 9 3 11 14
Output
438033477
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。