#P10267. 机器人
机器人
Background

Illustrator: 白森 さわ (from pixiv), please contact to remove if infringement.
Problem Description
Mafuyu is even too lazy to clean up bombs by herself, so Minami invented a fully automatic vacuum robot to clean the room.
Mafuyu’s room consists of rows and columns of tiles. The amount of dust on the tile in row , column is . Every day, Minami’s robot starts from the upper-left corner of the room, and each time it randomly moves one step either right or down.
If the robot reaches the lower-right corner without hitting a wall, it will return to Minami the xor sum of the dust amounts on all tiles it passed through. If the robot hits a wall before reaching the lower-right corner, meaning the target position of some step does not exist (moves outside the grid), then the robot returns an error value and stops moving.
Given the dust amount on every tile in Mafuyu’s room on a certain day, compute the expected value of the robot’s return value.
Formally, given an matrix , where the weight of cell is , a robot starts from . Each step, with probability it moves from to , and with probability it moves to . If it moves to , it returns the xor sum of the weights on the path. If at any time before reaching it moves outside the matrix, it returns . Find the expected value of the return value.
Output the answer modulo .
Input Format
The first line contains three integers , representing the number of rows, the number of columns, and the error value.
The next lines each contain integers. The integer in row , column is , describing the dust amount on each tile.
Output Format
Output one integer , the expected value modulo .
If you are confused about taking a rational number modulo, please refer to P2613 【Template】Modulo of Rational Numbers.
2 3 5
7 18 4
10 6 3
375000011
6 5 0
9 4 6 2 3
6 4 4 0 1
2 0 4 3 0
1 5 7 3 4
5 0 2 1 5
6 4 9 8 3
99609378
Hint
Sample Explanation
If the robot moves down on the first step, then:
-
If the robot moves down on the second step, it hits a wall and returns , with probability .
-
If the robot moves right on the second step, then:
-
If the robot moves down on the third step, it hits a wall and returns , with probability .
-
If the robot moves right on the third step, it reaches the lower-right corner and returns , with probability .
-
If the robot moves right on the first step, then:
-
If the robot moves down on the second step, then:
-
If the robot moves down on the third step, it hits a wall and returns , with probability .
-
If the robot moves right on the third step, it reaches the lower-right corner and returns , with probability .
-
-
If the robot moves right on the second step, then:
-
If the robot moves down on the third step, it reaches the lower-right corner and returns , with probability .
-
If the robot moves right on the third step, it hits a wall and returns , with probability .
-
Therefore, the expected return value is $\frac{3\times 5+8+16+18}{8}+\frac{5}{4}=\frac{67}{8}$, which is modulo .
Constraints
For all data, , .
There are test points in total. This problem uses bundled judging. The subtasks and test point distribution are as follows:
| Subtask ID | Test Point ID | Special Property | Score |
|---|---|---|---|
| No special restrictions |
Hint
denotes xor (bitwise xor). The xor sum of is .
Translated by ChatGPT 5