CF1740G.Dangerous Laser Power

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Pak Chanek has an n×mn \times m grid of portals. The portal on the ii-th row and jj-th column is denoted as portal (i,j)(i,j). The portals (1,1)(1,1) and (n,m)(n,m) are on the north-west and south-east corner of the grid respectively.

The portal (i,j)(i,j) has two settings:

  • Type ti,jt_{i,j}, which is either 00 or 11.
  • Strength si,js_{i,j}, which is an integer between 11 and 10910^9 inclusive.

Each portal has 44 faces labelled with integers 0,1,2,30,1,2,3, which correspond to the north, east, south, and west direction respectively.

When a laser enters face kk of portal (i,j)(i, j) with speed xinx_\text{in}, it leaves the portal going out of face (k+2+ti,j) mod 4(k+2+t_{i,j}) \bmod 4 with speed xout=max⁡(xin,si,j)x_\text{out} = \max(x_\text{in},s_{i,j}). The portal also has to consume xout−xinx_\text{out} - x_\text{in} units of energy.

Pak Chanek is very bored today. He will shoot 4nm4nm lasers with an initial speed of 11, one into each face of each portal. Each laser will travel throughout this grid of portals until it moves outside the grid or it has passed through 1010010^{100} portals.

At the end, Pak Chanek thinks that a portal is good if and only if the total energy consumed by that portal modulo 22 is equal to its type. Given the strength settings of all portals, find a way to assign the type settings of each portal such that the number of good portals is maximised.

帕克·查内克拥有一个 n×mn \times m 的传送门网格。第 ii 行第 jj 列的传送门记为传送门 (i,j)(i,j)。传送门 (1,1)(1,1) 和 (n,m)(n,m) 分别位于网格的西北角和东南角。

传送门 (i,j)(i,j) 具有两种属性:

  • 类型 ti,jt_{i,j},取值为 00 或 11;
  • 强度 si,js_{i,j},为介于 11 到 10910^9(含)之间的整数。

每个传送门有 44 个面,分别标号为整数 0,1,2,30,1,2,3,依次对应北、东、南、西方向。

当一束激光以入射速度 xinx_\text{in} 从传送门 (i,j)(i, j) 的第 kk 个面进入时,它将从编号为 (k+2+ti,j) mod 4(k+2+t_{i,j}) \bmod 4 的面射出,且出射速度为 xout=max⁡(xin,si,j)x_\text{out} = \max(x_\text{in},s_{i,j})。该传送门还需消耗 xout−xinx_\text{out} - x_\text{in} 单位的能量。

帕克·查内克今天非常无聊。他将向每个传送门的每个面各发射一束激光,共 4nm4nm 束,所有激光初始速度均为 11。每束激光将在该传送门网格中持续传播,直至移出网格边界,或已穿过 1010010^{100} 个传送门为止。

最终,帕克·查内克认为:一个传送门是“好”的,当且仅当该传送门所消耗的总能量对 22 取模的结果等于其类型 ti,jt_{i,j}。给定所有传送门的强度设置 si,js_{i,j},请为每个传送门分配类型 ti,jt_{i,j},使得“好”传送门的数量最大化。

输入格式

The first line contains two integers nn and mm (1≤n,m≤10001 \le n, m \le 1000) — the number of rows and columns in the grid.

The ii-th of the next nn lines contains mm integers, with the jj-th integer being si,js_{i,j} (1≤si,j≤1091 \leq s_{i,j} \leq 10^9) — the strength of portal (i,j)(i, j).

第一行包含两个整数 nn 和 mm(1≤n,m≤10001 \le n, m \le 1000)—— 分别表示网格的行数和列数。

接下来的 nn 行中,第 ii 行包含 mm 个整数,其中第 jj 个整数为 si,js_{i,j}(1≤si,j≤1091 \leq s_{i,j} \leq 10^9)—— 表示传送门 (i,j)(i, j) 的强度。

输出格式

Print nn lines with each line containing a string of length mm consisting of characters 00 or 11 representing the type settings. The jj-th character in the ii-th string is the type setting of portal (i,j)(i, j).

If there are multiple solutions, you can output any of them.

输出 nn 行,每行包含一个长度为 mm 的字符串,该字符串仅由字符 00 或 11 组成,表示排版设置。第 ii 行的第 jj 个字符表示传送门 (i,j)(i, j) 的排版设置。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    2 3
    8 8 2
    6 5 7

    输出#1

    110
    100
  • 输入#2

    1 2
    420 69

    输出#2

    10

说明/提示

In the first example, let's consider the laser Pak Chanek shoots into face 11 of portal (2,2)(2, 2). The laser travels as follows:

  1. The laser enters face 11 of portal (2,2)(2, 2) with speed 11. It leaves the portal going out of face 33 with speed 55. Portal (2,2)(2, 2) consumes 44 units of energy.
  2. The laser enters face 11 of portal (2,1)(2, 1) with speed 55. It leaves the portal going out of face 00 with speed 66. Portal (2,1)(2, 1) consumes 11 units of energy.
  3. The laser enters face 22 of portal (1,1)(1, 1) with speed 66. It leaves the portal going out of face 11 with speed 88. Portal (1,1)(1, 1) consumes 22 units of energy.
  4. The laser enters face 33 of portal (1,2)(1, 2) with speed 88. It leaves the portal going out of face 22 with speed 88. Portal (1,2)(1, 2) consumes 00 units of energy.
  5. The laser enters face 00 of portal (2,2)(2, 2) with speed 88. It leaves the portal going out of face 22 with speed 88. Portal (2,2)(2, 2) consumes 00 units of energy.

The illustration of the travel of the laser above is as follows.

As an example, consider portal (2,3)(2, 3). We can calculate that the total energy consumed by that portal in the end will be 3232. Since 32 mod 2=032 \bmod 2 = 0 and t2,3=0t_{2,3} = 0, then it is a good portal.

在第一个例子中,我们考虑 Pak Chanek 射向传送门 (2,2)(2, 2) 的第 11 个面的激光。该激光的传播路径如下:

  1. 激光以速度 11 进入传送门 (2,2)(2, 2) 的第 11 个面;随后以速度 55 从第 33 个面射出。传送门 (2,2)(2, 2) 消耗 44 单位能量。
  2. 激光以速度 55 进入传送门 (2,1)(2, 1) 的第 11 个面;随后以速度 66 从第 00 个面射出。传送门 (2,1)(2, 1) 消耗 11 单位能量。
  3. 激光以速度 66 进入传送门 (1,1)(1, 1) 的第 22 个面;随后以速度 88 从第 11 个面射出。传送门 (1,1)(1, 1) 消耗 22 单位能量。
  4. 激光以速度 88 进入传送门 (1,2)(1, 2) 的第 33 个面;随后以速度 88 从第 22 个面射出。传送门 (1,2)(1, 2) 消耗 00 单位能量。
  5. 激光以速度 88 进入传送门 (2,2)(2, 2) 的第 00 个面;随后以速度 88 从第 22 个面射出。传送门 (2,2)(2, 2) 消耗 00 单位能量。

上述激光传播过程的示意图如下所示。

举例来说,考虑传送门 (2,3)(2, 3)。我们可计算得出,该传送门最终消耗的总能量为 3232。由于 32 mod 2=032 \bmod 2 = 0 且 t2,3=0t_{2,3} = 0,因此它是一个“好传送门”。

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

首页