#abc271f. F - XOR on Grid Path
F - XOR on Grid Path
Score : points
问题描述
存在一个 行和 列的网格。我们用 表示从上到下的第 行()以及从左到右的第 列()的方格。
在方格 上有一个非负整数 。
当你位于方格 时,你可以移动到方格 或者 。请注意,你不能移出网格范围。
找出从方格 移动到方格 的路径数量,要求经过的所有方格(包括 和 )上的整数的异或和为 。
什么是异或和?两个整数 和 的异或和 定义如下:
- 若 和 在二进制表示中 位()恰有一个为 ,则 的二进制表示中 位为 ;否则,该位为 。
例如,(二进制表示:)。
一般情况下, 个整数 的异或和定义为 $(\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k)$。我们可以证明这个结果与 的顺序无关。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid with rows and columns. We denote by the square at the -th row from the top and -th column from the left.
Square has a non-negative integer written on it.
When you are at square , you can move to either square or . Here, you are not allowed to go outside the grid.
Find the number of ways to travel from square to square such that the exclusive logical sum of the integers written on the squares visited (including and ) is .
What is the exclusive logical sum? The exclusive logical sum of two integers and is defined as follows.
- The 's place () in the binary notation of is if exactly one of the 's places in the binary notation of and is ; otherwise, it is .
For example, (In binary notation: ).
In general, the exclusive logical sum of integers is defined as $(\cdots ((p_1 \oplus p_2) \oplus p_3) \oplus \cdots \oplus p_k)$. We can prove that it is independent of the order of .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 5 2
7 0 5
4 2 3
Sample Output 1
2
The following two ways satisfy the condition:
- $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3)$;
- $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$.
Sample Input 2
2
1 2
2 1
Sample Output 2
0
Sample Input 3
10
1 0 1 0 0 1 0 0 0 1
0 0 0 1 0 1 0 1 1 0
1 0 0 0 1 0 1 0 0 0
0 1 0 0 0 1 1 0 0 1
0 0 1 1 0 1 1 0 1 0
1 0 0 0 1 0 0 1 1 0
1 1 1 0 0 0 1 1 0 0
0 1 1 0 0 1 1 0 1 0
1 0 1 1 0 0 0 0 0 0
1 0 1 1 0 0 1 1 1 0
Sample Output 3
24307
update @ 2024/3/10 11:26:37