A high-security vault door has a front panel etched as an n x n grid of tumblers, each either engaged (1) or disengaged (0). To cast the matching back panel, the locksmith mirrors every row of the front panel left-to-right (reversing the order of tumblers within that row) and then flips the state of every tumbler in the mirrored row (engaged becomes disengaged, and disengaged becomes engaged). Given the front panel grid, print the resulting back panel grid.
n.n lines each contain n space-separated integers (each 0 or 1), the front panel's tumbler grid, row by row.Print n lines. Line i contains the n space-separated integers (each 0 or 1) of row i of the back panel, in the same row order as the input.
1 <= n <= 200 or 1.Example 1
Input
3 1 1 0 1 0 1 0 0 0
Expected
1 0 0 0 1 0 1 1 1
Explanation
Row [1,1,0] reversed is [0,1,1], then inverted (each 0<->1) gives [1,0,0]. Row [1,0,1] reversed is [1,0,1] (a palindrome), inverted gives [0,1,0]. Row [0,0,0] reversed is [0,0,0], inverted gives [1,1,1]. So the back panel is `1 0 0` / `0 1 0` / `1 1 1`.
Example 2
Input
4 1 1 0 0 1 0 0 1 0 1 1 1 1 0 1 0
Expected
1 1 0 0 0 1 1 0 0 0 0 1 1 0 1 0
Explanation
Row [1,1,0,0] reversed is [0,0,1,1], inverted gives [1,1,0,0]. Row [1,0,0,1] reversed is [1,0,0,1], inverted gives [0,1,1,0]. Row [0,1,1,1] reversed is [1,1,1,0], inverted gives [0,0,0,1]. Row [1,0,1,0] reversed is [0,1,0,1], inverted gives [1,0,1,0]. So the back panel is `1 1 0 0` / `0 1 1 0` / `0 0 0 1` / `1 0 1 0`.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →