loj#P555. 「LibreOJ Round #8」抢红包
「LibreOJ Round #8」抢红包
Description
Moejy0viiiiiv is collecting red envelopes on a rectangular plane. She starts at . Every day at noon, she walks from to with probability , and to with probability , and stops immediately with probability (once she stops, she will never move again). Besides, she also stops after walking for days.
With a given constant integer , there’s a red envelope at each . There’re also barriers at $(x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_K, y_K)$ (barriers never coincide with red envelopes). If she walks to a barrier, she will stop immediately.
Moejy0viiiiiv will collect each red envelope she passes by (including ). What’s the expected number of red envelopes Moejy0viiiiiv collects after days? Output the answer . Notice that .
Input Format
The first line contains two positive integers .
The second line contains four positive integers .
The following lines each contains two integers, the -th line contains .
Output Format
Output contains one integer, the expected number of red envelopes .
1 1
2 2 5 1
1 0
2
1 2
2 2 5 0
6
Constraints
For all test cases, $1 \leq N \leq 10^{18}, 0 \leq K \leq 50, 1 \leq D, M \leq 1000, 0 \leq x_1, x_2, ..., x_K \leq M$, $\forall i \in \{1, 2, 3, ..., K\}, D \nmid x_i \vee D \nmid y_i, x_i + y_i \leq N, 0 \leq A, B < 998244353$.
Detailed constraints are as follows (blank grids denote the same constraints as mentioned above):
Subtask # | Score (percentage) | ||||
---|---|---|---|---|---|
- | |||||
- | |||||
- | |||||
- |