QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#11377. 网格涂色

Statistiques

有一个 $2$ 行 $n$ 列的网格,行从上到下编号为 $1$ 到 $2$,列从左到右编号为 $1$ 到 $n$。共有 $2n$ 种颜色,编号为 $1$ 到 $2n$。网格中部分单元格已经着色,你需要对剩余的单元格进行着色(已经着色的单元格不能重新着色),使得相同颜色的四连通分量数量最少。请构造一个着色方案。

四连通是指如果两个相同颜色的单元格共享一条公共边,则这两个单元格被视为连通的。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10^5$)。

第二行包含 $n$ 个整数 $a_{1,1}, a_{1,2}, \dots, a_{1,n}$ ($0 \le a_{1,i} \le 2n$),表示网格第一行的着色情况。

第三行包含 $n$ 个整数 $a_{2,1}, a_{2,2}, \dots, a_{2,n}$ ($0 \le a_{2,i} \le 2n$),表示网格第二行的着色情况。

如果 $a_{i,j} = 0$,表示第 $i$ 行第 $j$ 列的单元格未着色;否则,它表示第 $i$ 行第 $j$ 列单元格的颜色为 $a_{i,j}$。保证至少有一个单元格初始已着色(即存在 $a_{i,j} \neq 0$)。

输出格式

输出两行,每行包含 $n$ 个正整数 $b_{i,j}$ ($1 \le b_{i,j} \le 2n$),表示一种着色方案。输出必须确保已经着色的单元格不能被重新着色,即对于 $a_{i,j} \neq 0$ 的单元格,必须满足 $b_{i,j} = a_{i,j}$。

如果存在多种合法的着色方案,输出其中任意一种即可。

样例

输入 1

5
1 0 1 0 2
3 3 2 0 4

输出 1

1 1 1 2 2
3 3 2 2 4

输入 2

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

输出 2

1 4 4 2 2 3
4 4 1 2 3 3

输入 3

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

输出 3

1 1 2 1 1 1
3 1 1 1 4 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.