CF1270I.Xor on Figures

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is given an integer kk and a grid 2k×2k2^k \times 2^k with some numbers written in its cells, cell (i,j)(i, j) initially contains number aija_{ij}. Grid is considered to be a torus, that is, the cell to the right of (i,2k)(i, 2^k) is (i,1)(i, 1), the cell below the (2k,i)(2^k, i) is (1,i)(1, i) There is also given a lattice figure FF, consisting of tt cells, where tt is odd. FF doesn't have to be connected.

We can perform the following operation: place FF at some position on the grid. (Only translations are allowed, rotations and reflections are prohibited). Now choose any nonnegative integer pp. After that, for each cell (i,j)(i, j), covered by FF, replace aija_{ij} by aij⊕pa_{ij}\oplus p, where ⊕\oplus denotes the bitwise XOR operation.

More formally, let FF be given by cells (x1,y1),(x2,y2),…,(xt,yt)(x_1, y_1), (x_2, y_2), \dots, (x_t, y_t). Then you can do the following operation: choose any x,yx, y with 1≤x,y≤2k1\le x, y \le 2^k, any nonnegative integer pp, and for every ii from 11 to nn replace number in the cell (((x+xi−1) mod 2k)+1,((y+yi−1) mod 2k)+1)(((x + x_i - 1)\bmod 2^k) + 1, ((y + y_i - 1)\bmod 2^k) + 1) with a((x+xi−1) mod 2k)+1,((y+yi−1) mod 2k)+1⊕pa_{((x + x_i - 1)\bmod 2^k) + 1, ((y + y_i - 1)\bmod 2^k) + 1}\oplus p.

Our goal is to make all the numbers equal to 00. Can we achieve it? If we can, find the smallest number of operations in which it is possible to do this.

给定一个整数 kk 和一个 2k×2k2^k \times 2^k 的网格,其中某些格子中写有数字;初始时,格子 (i,j)(i, j) 中的数字为 aija_{ij}。该网格被视为环面(torus),即:(i,2k)(i, 2^k) 右侧的格子为 (i,1)(i, 1),(2k,i)(2^k, i) 下方的格子为 (1,i)(1, i)。此外,还给定一个由 tt 个格子组成的格点图形 FF,其中 tt 为奇数;FF 不必连通。

我们可以执行如下操作:将 FF 放置在网格上的某个位置(仅允许平移,禁止旋转与反射)。随后任选一个非负整数 pp;接着,对 FF 所覆盖的每个格子 (i,j)(i, j),将其中的数 aija_{ij} 替换为 aij⊕pa_{ij}\oplus p,其中 ⊕\oplus 表示按位异或运算(bitwise XOR)。

更形式化地,设 FF 由格子 (x1,y1),(x2,y2),…,(xt,yt)(x_1, y_1), (x_2, y_2), \dots, (x_t, y_t) 组成。则可执行如下操作:任选满足 1≤x,y≤2k1\le x, y \le 2^k 的整数 x,yx, y,任选非负整数 pp,并对每个 i=1,2,…,ti = 1, 2, \dots, t,将格子

(((x+xi−1) mod 2k)+1,  ((y+yi−1) mod 2k)+1)(((x + x_i - 1)\bmod 2^k) + 1,\; ((y + y_i - 1)\bmod 2^k) + 1)

中的数值

a((x+xi−1) mod 2k)+1,  ((y+yi−1) mod 2k)+1a_{((x + x_i - 1)\bmod 2^k) + 1,\; ((y + y_i - 1)\bmod 2^k) + 1}

替换为

a((x+xi−1) mod 2k)+1,  ((y+yi−1) mod 2k)+1⊕p.a_{((x + x_i - 1)\bmod 2^k) + 1,\; ((y + y_i - 1)\bmod 2^k) + 1}\oplus p.

我们的目标是使网格中所有数字均变为 00。能否实现这一目标?若能,请找出达成目标所需的最少操作次数。

输入格式

The first line contains a single integer kk (1≤k≤91 \le k \le 9).

The ii-th of the next 2k2^k lines contains 2k2^k integers ai1,ai2,…,ai2ka_{i1}, a_{i2}, \dots, a_{i2^k} (0≤aij<2600 \le a_{ij} \lt 2^{60}) — initial values in the ii-th row of the grid.

The next line contains a single integer tt (1≤t≤min⁡(99,4k)1\le t \le \min(99, 4^k), tt is odd) — number of cells of figure.

ii-th of next tt lines contains two integers xix_i and yiy_i (1≤xi,yi≤2k1 \le x_i, y_i \le 2^k), describing the position of the ii-th cell of the figure.

It is guaranteed that all cells are different, but it is not guaranteed that the figure is connected.

第一行包含一个整数 kk(1≤k≤91 \le k \le 9)。

接下来的 2k2^k 行中,第 ii 行包含 2k2^k 个整数 ai1,ai2,…,ai2ka_{i1}, a_{i2}, \dots, a_{i2^k}(0≤aij<2600 \le a_{ij} \lt 2^{60}),表示网格第 ii 行的初始值。

下一行包含一个整数 tt(1≤t≤min⁡(99,4k)1\le t \le \min(99, 4^k),且 tt 为奇数),表示该图形所占的格子数量。

接下来的 tt 行中,第 ii 行包含两个整数 xix_i 和 yiy_i(1≤xi,yi≤2k1 \le x_i, y_i \le 2^k),描述该图形第 ii 个格子的位置。

保证所有格子互不相同,但不保证该图形是连通的。

输出格式

If it is impossible to make all numbers in the grid equal to 00 with these operations, output −1-1.

Otherwise, output a single integer — the minimal number of operations needed to do this. It can be shown that if it is possible to make all numbers equal 00, it is possible to do so in less than 101810^{18} operations.

如果无法通过这些操作使网格中的所有数字都变为 00,则输出 −1-1。

否则,输出一个整数——完成此目标所需的最少操作次数。可以证明:如果能够将所有数字变为 00,那么一定能在少于 101810^{18} 次操作内完成。

输入输出样例

  • 输入#1

    2
    5 5 5 5
    2 6 2 3
    0 0 2 0
    0 0 0 0
    5
    1 1
    1 2
    1 3
    1 4
    2 4

    输出#1

    3

说明/提示

The figure and the operations for the example are shown above:

上图展示了示例中的图形及对应操作:

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

首页