logo AlgoBeat OnlineJudge
登录 注册

#216198. [ICPC 2018 NAIPC] Recovery

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Consider an matrix of ones and zeros. For example, this :

We can compute even parity for each row, and each column. In this case, the row parities are and the column parities are (the parity is 1 if there is an odd number of 1s in the row or column, 0 if the number of 1s is even). Note that the top row is row 1, the bottom row is row , the leftmost column is column 1, and the rightmost column is column .

Suppose we lost the original matrix, and only have the row and column parities. Can we recover the original matrix? Unfortunately, we cannot uniquely recover the original matrix, but with some constraints, we can uniquely recover a matrix that fits the bill. Firstly, the recovered matrix must contain as many 1’s as possible. Secondly, of all possible recovered matrices with the most 1’s, use the one which has the smallest binary value when you start with row 1, concatenate row 2 to the end of row 1, then append row 3, row 4, and so on.

输入格式

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will consist of exactly two lines. The first line will contain a string (), consisting only of the characters 0 and 1. These are the row parities, in order. The second line will contain a string (), consisting only of the characters 0 and 1. These are the column parities, in order.

输出格式

If it is possible to recover the original matrix with the given constraints, then output the matrix as lines of exactly characters, consisting only of 0’s and 1’s. If it is not possible to recover the original matrix, output .

样例

样例输入 1

0110
1001

样例输出 1

1111
0111
1110
1111

样例输入 2

0
1

样例输出 2

-1

样例输入 3

11
0110

样例输出 3

1011
1101