#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 nn rows and mm columns of tiles. The amount of dust on the tile in row ii, column jj is ai,ja_{i,j}. 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 xx 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 n×mn \times m matrix aa, where the weight of cell (i,j)(i,j) is ai,ja_{i,j}, a robot starts from (1,1)(1,1). Each step, with probability 12\frac{1}{2} it moves from (i,j)(i,j) to (i,j+1)(i,j+1), and with probability 12\frac{1}{2} it moves to (i+1,j)(i+1,j). If it moves to (n,m)(n,m), it returns the xor sum of the weights on the path. If at any time before reaching (n,m)(n,m) it moves outside the matrix, it returns xx. Find the expected value of the return value.

Output the answer modulo 109+710^9+7.

Input Format

The first line contains three integers n,m,xn,m,x, representing the number of rows, the number of columns, and the error value.

The next nn lines each contain mm integers. The integer in row ii, column jj is ai,ja_{i,j}, describing the dust amount on each tile.

Output Format

Output one integer ansans, the expected value modulo 109+710^9+7.

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 1\mathbf{1} 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 55, with probability 14\frac{1}{4}.

  • 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 55, with probability 18\frac{1}{8}.

    • If the robot moves right on the third step, it reaches the lower-right corner and returns 71063=87\oplus 10\oplus 6\oplus 3=8, with probability 18\frac{1}{8}.

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 55, with probability 18\frac{1}{8}.

    • If the robot moves right on the third step, it reaches the lower-right corner and returns 71863=167\oplus 18\oplus 6\oplus 3=16, with probability 18\frac{1}{8}.

  • 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 71843=187\oplus 18\oplus 4\oplus 3=18, with probability 18\frac{1}{8}.

    • If the robot moves right on the third step, it hits a wall and returns 55, with probability 18\frac{1}{8}.

Therefore, the expected return value is $\frac{3\times 5+8+16+18}{8}+\frac{5}{4}=\frac{67}{8}$, which is 375000011375000011 modulo 109+710^9+7.

Constraints

For all data, 1n,m1031\leq n,m\leq 10^3, 0ai,j,x1090\leq a_{i,j},x\leq 10^9.

There are 2222 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
00 141\sim 4 n,m12n,m\leq 12 1010
11 585\sim 8 n,m20n,m\leq 20 2020
22 9129\sim 12 ai,j20a_{i,j}\leq 20
33 131613\sim 16 x=0x=0
44 172217\sim 22 No special restrictions 3030

Hint

\oplus denotes xor (bitwise xor). The xor sum of x1,x2,x3,,xnx_1,x_2,x_3,\cdots,x_n is x1x2x3xnx_1\oplus x_2\oplus x_3\oplus\cdots \oplus x_n.

Translated by ChatGPT 5