AT_arc225_a.Four Coloring

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There is an N×NN \times N grid XX. Let (i,j)(i,j) denote the cell at the ii-th row from the top and the jj-th column from the left. We call two cells that share an edge adjacent.

Cell (i,j)(i,j) is painted with color Xi,jX_{i,j}. The color is one of 1,2,3,41,2,3,4, and adjacent cells are painted with different colors.

You will prepare an N×NN \times N grid YY and paint each cell. Let Yi,jY_{i,j} denote the color painted on cell (i,j)(i,j) of YY.

Find one way of painting that satisfies the following conditions.

  • The color of each cell of YY is one of 1,2,3,41,2,3,4. Adjacent cells may have the same color.

  • For any two adjacent cells (i1,j1)(i_1,j_1) and (i2,j2)(i_2,j_2), the following holds.

  • If ∣Xi1,j1−Xi2,j2∣=1|X_{i_1,j_1} - X_{i_2,j_2}|=1, then ∣Yi1,j1−Yi2,j2∣≥2|Y_{i_1,j_1} - Y_{i_2,j_2}|\ge 2.

  • If ∣Xi1,j1−Xi2,j2∣≥2|X_{i_1,j_1} - X_{i_2,j_2}|\ge2, then ∣Yi1,j1−Yi2,j2∣≤1|Y_{i_1,j_1} - Y_{i_2,j_2}|\le 1.

It can be proved that a way of painting satisfying the conditions always exists.

存在一个 N×NN \times N 的网格 XX。记 (i,j)(i,j) 表示从上往下数第 ii 行、从左往右数第 jj 列的格子。我们将共享一条边的两个格子称为相邻。

格子 (i,j)(i,j) 被染成颜色 Xi,jX_{i,j}。颜色取自 {1,2,3,4}\{1,2,3,4\},且任意两个相邻格子的颜色互不相同。

你需要构造一个 N×NN \times N 的网格 YY 并对每个格子染色。记 Yi,jY_{i,j} 表示 YY 中格子 (i,j)(i,j) 所染的颜色。

请找出一种满足以下条件的染色方案:

  • YY 中每个格子的颜色取自 {1,2,3,4}\{1,2,3,4\}。相邻格子的颜色可以相同。

  • 对任意一对相邻格子 (i1,j1)(i_1,j_1) 和 (i2,j2)(i_2,j_2),满足以下条件:

    • 若 ∣Xi1,j1−Xi2,j2∣=1|X_{i_1,j_1} - X_{i_2,j_2}|=1,则 ∣Yi1,j1−Yi2,j2∣≥2|Y_{i_1,j_1} - Y_{i_2,j_2}|\ge 2;
    • 若 ∣Xi1,j1−Xi2,j2∣≥2|X_{i_1,j_1} - X_{i_2,j_2}|\ge2,则 ∣Yi1,j1−Yi2,j2∣≤1|Y_{i_1,j_1} - Y_{i_2,j_2}|\le 1。

可以证明:满足上述条件的染色方案一定存在。

输入格式

The input is given from Standard Input in the following format:

NN
X1,1X_{1,1} X1,2X_{1,2} …\ldots X1,NX_{1,N}
X2,1X_{2,1} X2,2X_{2,2} …\ldots X2,NX_{2,N}
⋮\vdots
XN,1X_{N,1} XN,2X_{N,2} …\ldots XN,NX_{N,N}

输入从标准输入给出,格式如下:

NN
X1,1X_{1,1} X1,2X_{1,2} …\ldots X1,NX_{1,N}
X2,1X_{2,1} X2,2X_{2,2} …\ldots X2,NX_{2,N}
⋮\vdots
XN,1X_{N,1} XN,2X_{N,2} …\ldots XN,NX_{N,N}

输出格式

Output a YY satisfying the conditions in the following format:

Y1,1Y_{1,1} Y1,2Y_{1,2} …\ldots Y1,NY_{1,N}
Y2,1Y_{2,1} Y2,2Y_{2,2} …\ldots Y2,NY_{2,N}
⋮\vdots
YN,1Y_{N,1} YN,2Y_{N,2} …\ldots YN,NY_{N,N}

输出一个满足以下条件的 YY,格式如下:

Y1,1Y_{1,1} Y1,2Y_{1,2} …\ldots Y1,NY_{1,N}
Y2,1Y_{2,1} Y2,2Y_{2,2} …\ldots Y2,NY_{2,N}
⋮\vdots
YN,1Y_{N,1} YN,2Y_{N,2} …\ldots YN,NY_{N,N}

输入输出样例

  • 输入#1

    3
    1 2 3
    2 1 4
    1 3 2

    输出#1

    4 1 4
    1 3 2
    4 4 2
  • 输入#2

    2
    1 4
    4 1

    输出#2

    1 1
    1 1

说明/提示

Sample 1 Explanation:
For the input XX and the output YY, for example, looking at the two adjacent cells (1,1)(1,1) and (1,2)(1,2), we have the following.

  • ∣X1,1−X1,2∣=∣1−2∣=1|X_{1,1} - X_{1,2}| = |1 - 2| = 1
  • ∣Y1,1−Y1,2∣=∣4−1∣=3|Y_{1,1} - Y_{1,2}| = |4 - 1| = 3

Also, looking at the two adjacent cells (2,2)(2,2) and (3,2)(3,2), we have the following.

  • ∣X2,2−X3,2∣=∣1−3∣=2|X_{2,2} - X_{3,2}| = |1 - 3| = 2
  • ∣Y2,2−Y3,2∣=∣3−4∣=1|Y_{2,2} - Y_{3,2}| = |3 - 4| = 1

In this way, it can be confirmed that YY satisfies the conditions for any two adjacent cells, so this is a correct answer.

Sample 2 Explanation:
Adjacent cells of YY may have the same color.

Constraints

  • 2≤N≤5002 \le N \le 500
  • 1≤Xi,j≤41 \le X_{i,j} \le 4
  • Adjacent cells of XX are painted with different colors.
  • All input values are integers.

样例 1 解释:
对于输入 XX 和输出 YY,例如考察相邻的两个格子 (1,1)(1,1) 和 (1,2)(1,2),我们有以下关系:

  • ∣X1,1−X1,2∣=∣1−2∣=1|X_{1,1} - X_{1,2}| = |1 - 2| = 1
  • ∣Y1,1−Y1,2∣=∣4−1∣=3|Y_{1,1} - Y_{1,2}| = |4 - 1| = 3

再考察相邻的两个格子 (2,2)(2,2) 和 (3,2)(3,2),我们有以下关系:

  • ∣X2,2−X3,2∣=∣1−3∣=2|X_{2,2} - X_{3,2}| = |1 - 3| = 2
  • ∣Y2,2−Y3,2∣=∣3−4∣=1|Y_{2,2} - Y_{3,2}| = |3 - 4| = 1

以此类推,可以验证:对任意一对相邻格子,YY 均满足题目条件,因此这是一个正确答案。

样例 2 解释:
YY 中的相邻格子可以具有相同的颜色。

约束条件

  • 2≤N≤5002 \le N \le 500
  • 1≤Xi,j≤41 \le X_{i,j} \le 4
  • XX 中的相邻格子颜色互不相同。
  • 所有输入值均为整数。

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

首页