QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#11295. 贪吃蛇

统计

一条蛇完全填满了一个 $3 \times n$ 的棋盘。蛇的连续部分编号从 $1$ 到 $3n$。编号连续的部分(即 $1$ 和 $2$,$2$ 和 $3$,$3$ 和 $4$ 等)占据的方格必须共享一条边。例如,一条蛇可以按如下方式填满一个 $3 \times 9$ 的棋盘:

棋盘中部分方格的蛇身编号已被擦除。你能还原这条蛇吗?

输入格式

标准输入的第一行包含一个整数 $n$ ($1 \le n \le 1\,000$),表示棋盘的长度。接下来的三行描述了棋盘;其中第 $i$ 行包含 $n$ 个整数 $a_{ij}$ ($0 \le a_{ij} \le 3n$,对于 $1 \le j \le n$)。如果 $a_{ij} > 0$,则 $a_{ij}$ 是占据棋盘第 $i$ 行第 $j$ 列方格的蛇身编号。如果 $a_{ij} = 0$,则该方格的蛇身编号未知。

输出格式

你的程序应向标准输出打印三行。第 $i$ 行应包含 $n$ 个正整数 $b_{ij}$ (对于 $1 \le j \le n$)。所有数字 $b_{ij}$ 共同构成 $1$ 到 $3n$ 的一个排列。输出的数字应为蛇的一种有效还原,即它们必须与输入的(正数)编号一致,并满足上述约束条件。

你可以假设至少存在一种有效的蛇身还原方案。如果存在多种方案,你的程序可以打印其中任意一种。

样例

输入 1

9
0 0 5 0 17 0 0 0 21
8 0 0 3 16 0 0 25 0
0 0 0 0 0 0 0 0 23

输出 1

7 6 5 4 17 18 19 20 21
8 1 2 3 16 15 26 25 22
9 10 11 12 13 14 27 24 23

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.