CF1740G.Dangerous Laser Power

普及/提高-

通过率:0%

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)mod4(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 xoutxinx_\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.

输入格式

The first line contains two integers nn and mm ( 1n,m10001 \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} ( 1si,j1091 \leq s_{i,j} \leq 10^9 ) — the strength of portal (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.

输入输出样例

  • 输入#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 32mod2=032 \bmod 2 = 0 and t2,3=0t_{2,3} = 0 , then it is a good portal.

首页