CF1628C.Grid Xor

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Note: The XOR-sum of set s1,s2,…,sm{s_1,s_2,\ldots,s_m} is defined as s1⊕s2⊕…⊕sms_1 \oplus s_2 \oplus \ldots \oplus s_m, where ⊕\oplus denotes the bitwise XOR operation.

After almost winning IOI, Victor bought himself an n×nn\times n grid containing integers in each cell. nn is an even integer. The integer in the cell in the ii-th row and jj-th column is ai,ja_{i,j}.

Sadly, Mihai stole the grid from Victor and told him he would return it with only one condition: Victor has to tell Mihai the XOR-sum of all the integers in the whole grid.

Victor doesn't remember all the elements of the grid, but he remembers some information about it: For each cell, Victor remembers the XOR-sum of all its neighboring cells.

Two cells are considered neighbors if they share an edge — in other words, for some integers 1≤i,j,k,l≤n1 \le i, j, k, l \le n, the cell in the ii-th row and jj-th column is a neighbor of the cell in the kk-th row and ll-th column if ∣i−k∣=1|i - k| = 1 and j=lj = l, or if i=ki = k and ∣j−l∣=1|j - l| = 1.

To get his grid back, Victor is asking you for your help. Can you use the information Victor remembers to find the XOR-sum of the whole grid?

It can be proven that the answer is unique.

注意:集合 {s1,s2,…,sm}\{s_1,s_2,\ldots,s_m\} 的异或和(XOR-sum)定义为 s1⊕s2⊕…⊕sms_1 \oplus s_2 \oplus \ldots \oplus s_m,其中 ⊕\oplus 表示按位异或运算。

在几乎赢得国际信息学奥林匹克竞赛(IOI)后,Victor 给自己买了一个 n×nn\times n 的网格,每个格子中填有一个整数。nn 是一个偶数。第 ii 行第 jj 列格子中的整数为 ai,ja_{i,j}。

不幸的是,Mihai 从 Victor 那里偷走了这个网格,并告诉他:只有当 Victor 能告诉 Mihai 整个网格中所有整数的异或和时,他才会将网格归还。

Victor 并不记得网格中所有元素的具体值,但他还记得关于该网格的一些信息:对于每个格子,Victor 记得其所有相邻格子中整数的异或和。

若两个格子共享一条边,则称它们互为邻居——换言之,对任意整数 1≤i,j,k,l≤n1 \le i, j, k, l \le n,第 ii 行第 jj 列的格子与第 kk 行第 ll 列的格子互为邻居,当且仅当 ∣i−k∣=1|i - k| = 1 且 j=lj = l,或者 i=ki = k 且 ∣j−l∣=1|j - l| = 1。

为了拿回自己的网格,Victor 向你求助。你能利用 Victor 所记得的信息,求出整个网格所有整数的异或和吗?

可以证明,该问题的答案是唯一的。

输入格式

The first line of the input contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single even integer nn (2≤n≤10002 \leq n \leq 1000) — the size of the grid.

Then follows nn lines, each containing nn integers. The jj-th integer in the ii-th of these lines represents the XOR-sum of the integers in all the neighbors of the cell in the ii-th row and jj-th column.

It is guaranteed that the sum of nn over all test cases doesn't exceed 10001000 and in the original grid 0≤ai,j≤230−10 \leq a_{i, j} \leq 2^{30} - 1.

Hack Format

To hack a solution, use the following format:

The first line should contain a single integer t (1≤t≤1001 \le t \le 100) — the number of test cases.

The first line of each test case should contain a single even integer nn (2≤n≤10002 \leq n \leq 1000) — the size of the grid.

Then nn lines should follow, each containing nn integers. The jj-th integer in the ii-th of these lines is ai,ja_{i,j} in Victor's original grid. The values in the grid should be integers in the range [0,230−1][0, 2^{30}-1]

The sum of nn over all test cases must not exceed 10001000.

输入的第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个偶数 nn(2≤n≤10002 \leq n \leq 1000)—— 表示网格的大小。

接下来是 nn 行,每行包含 nn 个整数。在这些行中,第 ii 行的第 jj 个整数表示原始网格中第 ii 行第 jj 列单元格的所有相邻单元格内整数的异或和(XOR-sum)。

保证所有测试用例的 nn 之和不超过 10001000,且在 Victor 的原始网格中满足 0≤ai,j≤230−10 \leq a_{i, j} \leq 2^{30} - 1。

Hack 格式

要对某个解法进行 Hack,需使用如下格式:

第一行应包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 表示测试用例的数量。

每个测试用例的第一行应包含一个偶数 nn(2≤n≤10002 \leq n \leq 1000)—— 表示网格的大小。

随后应有 nn 行,每行包含 nn 个整数。其中第 ii 行的第 jj 个整数即为 Victor 原始网格中的 ai,ja_{i,j}。网格中的数值应为区间 [0,230−1][0, 2^{30}-1] 内的整数。

所有测试用例的 nn 之和不得超过 10001000。

输出格式

For each test case, output a single integer — the XOR-sum of the whole grid.

对于每个测试用例,输出一个整数——整个网格的异或和。

输入输出样例

  • 输入#1

    3
    2
    1 5
    5 1
    4
    1 14 8 9
    3 1 5 9
    4 13 11 1
    1 15 4 11
    4
    2 4 1 6
    3 7 3 10
    15 9 4 2
    12 7 15 1

    输出#1

    4
    9
    5

说明/提示

For the first test case, one possibility for Victor's original grid is:

11

33

22

44

For the second test case, one possibility for Victor's original grid is:

33

88

88

55

99

55

55

11

55

55

99

99

88

44

22

99

For the third test case, one possibility for Victor's original grid is:

44

33

22

11

11

22

33

44

55

66

77

88

88

99

99

11

对于第一个测试用例,Victor 原始网格的一种可能为:

11

33

22

44

对于第二个测试用例,Victor 原始网格的一种可能为:

33

88

88

55

99

55

55

11

55

55

99

99

88

44

22

99

对于第三个测试用例,Victor 原始网格的一种可能为:

44

33

22

11

11

22

33

44

55

66

77

88

88

99

99

11

输入解题思路,AI测评打分。不知道怎么写?

首页