Logo
(追記) (追記ここまで)

16047번 - Recovery 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB72201929.231%

문제

Consider an n × m matrix of ones and zeros. For example, this 4 × 4:

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

We can compute even parity for each row, and each column. In this case, the row parities are [0, 1, 1, 0] and the column parities are [1, 0, 0, 1] (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 n, the leftmost column is column 1, and the rightmost column is column m.

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 R (1 ≤ |R| ≤ 50), consisting only of the characters 0 and 1. These are the row parities, in order. The second line will contain a string C (1 ≤ |C| ≤ 50), 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 |R| lines of exactly |C| characters, consisting only of 0’s and 1’s. If it is not possible to recover the original matrix, output −1.

제한

예제 입력 1

0110
1001

예제 출력 1

1111
0111
1110
1111

예제 입력 2

0
1

예제 출력 2

-1

예제 입력 3

11
0110

예제 출력 3

1011
1101

힌트

출처

University > North American Invitational Programming Contest > NAIPC 2018 H번

Contest > Open Cup > 2017/2018 Season > Stage 16: Grand Prix of America H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /