AT_arc225_a.Four Coloring
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an N×N grid X. Let (i,j) denote the cell at the i-th row from the top and the j-th column from the left. We call two cells that share an edge adjacent.
Cell (i,j) is painted with color Xi,j. The color is one of 1,2,3,4, and adjacent cells are painted with different colors.
You will prepare an N×N grid Y and paint each cell. Let Yi,j denote the color painted on cell (i,j) of Y.
Find one way of painting that satisfies the following conditions.
-
The color of each cell of Y is one of 1,2,3,4. Adjacent cells may have the same color.
-
For any two adjacent cells (i1,j1) and (i2,j2), the following holds.
-
If ∣Xi1,j1−Xi2,j2∣=1, then ∣Yi1,j1−Yi2,j2∣≥2.
-
If ∣Xi1,j1−Xi2,j2∣≥2, then ∣Yi1,j1−Yi2,j2∣≤1.
It can be proved that a way of painting satisfying the conditions always exists.
存在一个 N×N 的网格 X。记 (i,j) 表示从上往下数第 i 行、从左往右数第 j 列的格子。我们将共享一条边的两个格子称为相邻。
格子 (i,j) 被染成颜色 Xi,j。颜色取自 {1,2,3,4},且任意两个相邻格子的颜色互不相同。
你需要构造一个 N×N 的网格 Y 并对每个格子染色。记 Yi,j 表示 Y 中格子 (i,j) 所染的颜色。
请找出一种满足以下条件的染色方案:
-
Y 中每个格子的颜色取自 {1,2,3,4}。相邻格子的颜色可以相同。
-
对任意一对相邻格子 (i1,j1) 和 (i2,j2),满足以下条件:
- 若 ∣Xi1,j1−Xi2,j2∣=1,则 ∣Yi1,j1−Yi2,j2∣≥2;
- 若 ∣Xi1,j1−Xi2,j2∣≥2,则 ∣Yi1,j1−Yi2,j2∣≤1。
可以证明:满足上述条件的染色方案一定存在。
输入格式
The input is given from Standard Input in the following format:
N
X1,1 X1,2 … X1,N
X2,1 X2,2 … X2,N
⋮
XN,1 XN,2 … XN,N
输入从标准输入给出,格式如下:
N
X1,1 X1,2 … X1,N
X2,1 X2,2 … X2,N
⋮
XN,1 XN,2 … XN,N
输出格式
Output a Y satisfying the conditions in the following format:
Y1,1 Y1,2 … Y1,N
Y2,1 Y2,2 … Y2,N
⋮
YN,1 YN,2 … YN,N
输出一个满足以下条件的 Y,格式如下:
Y1,1 Y1,2 … Y1,N
Y2,1 Y2,2 … Y2,N
⋮
YN,1 YN,2 … YN,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 X and the output Y, for example, looking at the two adjacent cells (1,1) and (1,2), we have the following.
- ∣X1,1−X1,2∣=∣1−2∣=1
- ∣Y1,1−Y1,2∣=∣4−1∣=3
Also, looking at the two adjacent cells (2,2) and (3,2), we have the following.
- ∣X2,2−X3,2∣=∣1−3∣=2
- ∣Y2,2−Y3,2∣=∣3−4∣=1
In this way, it can be confirmed that Y satisfies the conditions for any two adjacent cells, so this is a correct answer.
Sample 2 Explanation:
Adjacent cells of Y may have the same color.
Constraints
- 2≤N≤500
- 1≤Xi,j≤4
- Adjacent cells of X are painted with different colors.
- All input values are integers.
样例 1 解释:
对于输入 X 和输出 Y,例如考察相邻的两个格子 (1,1) 和 (1,2),我们有以下关系:
- ∣X1,1−X1,2∣=∣1−2∣=1
- ∣Y1,1−Y1,2∣=∣4−1∣=3
再考察相邻的两个格子 (2,2) 和 (3,2),我们有以下关系:
- ∣X2,2−X3,2∣=∣1−3∣=2
- ∣Y2,2−Y3,2∣=∣3−4∣=1
以此类推,可以验证:对任意一对相邻格子,Y 均满足题目条件,因此这是一个正确答案。
样例 2 解释:
Y 中的相邻格子可以具有相同的颜色。
约束条件
- 2≤N≤500
- 1≤Xi,j≤4
- X 中的相邻格子颜色互不相同。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?