QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#3021. 恢复

الإحصائيات

考虑一个 $n \times m$ 的由 0 和 1 组成的矩阵。例如,下面是一个 $4 \times 4$ 的矩阵:

1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 0

我们可以计算每一行和每一列的奇偶校验位。在本例中,行校验位为 $[0, 1, 1, 0]$,列校验位为 $[1, 0, 0, 1]$(如果行或列中 1 的个数为奇数,则校验位为 1;如果 1 的个数为偶数,则校验位为 0)。注意,最顶行为第 1 行,最底行为第 $n$ 行,最左列为第 1 列,最右列为第 $m$ 列。

假设我们丢失了原始矩阵,只剩下行和列的校验位。我们能恢复原始矩阵吗?遗憾的是,我们无法唯一地恢复原始矩阵,但在某些约束条件下,我们可以唯一地恢复一个符合要求的矩阵。首先,恢复出的矩阵必须包含尽可能多的 1。其次,在所有包含最多 1 的恢复矩阵中,选择一个二进制数值最小的矩阵,其定义为:从第 1 行开始,将第 2 行连接到第 1 行末尾,然后依次连接第 3 行、第 4 行,以此类推。

输入格式

每个输入包含一个测试用例。注意,你的程序可能会在不同的输入上运行多次。每个测试用例包含恰好两行。第一行包含一个字符串 $R$ ($1 \le |R| \le 50$),仅由字符 0 和 1 组成,按顺序表示行校验位。第二行包含一个字符串 $C$ ($1 \le |C| \le 50$),仅由字符 0 和 1 组成,按顺序表示列校验位。

输出格式

如果可以在给定约束下恢复原始矩阵,则输出该矩阵,共 $|R|$ 行,每行恰好 $|C|$ 个字符,仅由 0 和 1 组成。如果无法恢复原始矩阵,则输出 $-1$。

样例

样例输入 1

0110
1001

样例输出 1

1111
0111
1110
1111

样例输入 2

0
1

样例输出 2

-1

样例输入 3

11
0110

样例输出 3

1011
1101

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.