#P8558. 黑暗(Darkness)
黑暗(Darkness)
Problem Description
Ling is searching for Mio in a dark three-dimensional space. This space can be represented as $\{(x,y,z) \mid x \in[0,A],y \in [0,B],z\in [0,C] \}$. Ling initially stands at , and Mio stands at . Suppose Ling is at . Each time she moves, she tries to move uniformly at random to , or , or .
The outer boundary of this space is made of walls and cannot be passed through. Because it is very dark, Ling does not know whether she has reached a wall. That is, when she randomly chooses one of the three directions to try to move, she may hit a wall.
Ling wants to know the expected value of the -th power of the “Manhattan distance to Mio (in this problem, it is the sum of the coordinates)” at the moment she hits a wall for the first time.
You only need to output the result modulo .
Input Format
Input one line with four positive integers .
Output Format
Output one line with one integer, representing the answer.
1 1 1 1
443664158
2 3 4 2
128260948
4 6 9 2
622775535
58 88 133 233
128518400
114514 1919810 4999231 8214898
823989766
Hint
[Sample Explanation.]
The table below lists the probability of reaching each position and hitting a wall there:
You can see that only at these positions is it possible to hit a wall. From this, the expected value is , which is modulo .
[Sample Explanation.]
Here you need to compute the expected value of the square of the distance. The actual answers are and , respectively.
[Constraints.]
This problem uses bundled testdata.
Subtask 1 (8 pts): .
Subtask 2 (19 pts): .
Subtask 3 (13 pts): .
Subtask 4 (23 pts): .
Subtask 5 (37 pts): no special restrictions.
For of the testdata, , .
[Hint.]
For a discrete random variable , let the probability that it takes value be . Then the expected value of is defined as:
For a rational number ( are both positive integers), if an integer satisfies and , then is the result of modulo .
Translated by ChatGPT 5