Good and Lucky Matrices
Time limit2sMemory limit1024 MB
Given an n x n binary matrix of one type (good or lucky), map it injectively to a matrix of the other type so the mapping is a bijection.
- Level
Hard10 of 10
- Topics
- Combinatorics, Math, Matrix
- Solved
- No attempts yet
Problem
A square binary matrix is good if and only if its determinant is odd.
A binary matrix of size is lucky if and only if the greedy matching algorithm below finds a matching of size . The algorithm reads the matrix line by line, from top to bottom. On each line, if there is a in a column that was never chosen before, the algorithm chooses the leftmost such column.
You must compare the numbers of good and lucky matrices of size . To do that, you must build a bijection between the smaller set and an equinumerous subset of the larger set.
Input
The first line contains an integer , the number of test cases. The test cases follow.
The first line of each test case contains the string good or lucky, which gives the type of matrix. The next line contains a single integer (), the size of the matrix. Then lines follow. The -th of them contains a binary string of length exactly , the -th row of the matrix.
The matrices given on the second run are exactly the same as the matrices your program printed on the first run, in the same order. The sum of over all test cases does not exceed 2000.
Output
On each run, print answers. Each answer is either a single integer on its own line, or a matrix of the opposite type formatted like the input: a line with , followed by lines that describe the rows.
The mapping must be a bijection. If your answer on the first run for matrix of some type was matrix , and your answer on the second run for of the opposite type was matrix , then must hold. For each and each matrix type, let be the set of all matrices of this type and the set of all matrices of the other type. You may answer for at most different matrices from .