This must be an easy task, because it only deals with a few zeros and ones, and we even placed it first in the problem set.
You will be given a positive integer \(n\).
Your task is to construct any one grid of \(n\times n\) zeros and ones with the following properties:
In each row and each column, the number of 0s and the number of 1s differ by at most one. (I.e., they differ by 1 if \(n\) is odd and they are equal if \(n\) is even.)
In each row and each column there are never three consecutive equal values.
The \(2n\) bit strings obtained by reading each row left to right and each column top to bottom are all mutually distinct.
The first line of each input file contains the number \(t\) of test cases. The specified number of test cases follows, one after another.
Each test case consists of a single line with a single positive integer \(n\).
For a test case that contains the integer \(n\), output either:
Input file: E1.in
There are \(t=35\) test cases, the biggest of them has \(n=500\).
Your score is calculated as follows:
input2 3 6 | outputIMPOSSIBLE POSSIBLE 110100 001011 101010 010101 001101 110010 |
The example input contains \(t=2\) test cases.
The first test case has \(n=3\). Each row and each column of the grid must have two 0s and one 1 or vice versa. As they all have to be mutually distinct, each of the sequences 001, 010, 011, 100, 101 and 110 must appear exactly once. However, there’s obviously no such grid. (One easy argument why: in these strings there are 9 zeros in total, and we cannot have 4.5 zeros in the grid.)
The second test case has \(n=6\). The example output shows one valid \(6\times 6\) grid.
In the above grid: