#C7157. Unique Grid Puzzle
Unique Grid Puzzle
Unique Grid Puzzle
You are given two integers (R) and (C) representing the number of rows and columns of a grid. Your task is to fill the grid with consecutive positive integers starting from 1 such that every row and every column contains unique integers. However, if either (R > 100) or (C > 100), then it is impossible to create the grid and you should output Impossible instead.
Constraints:
- \(1 \le R, C \le 100\) for possible grids.
- If either dimension exceeds 100, output "Impossible".
Note: The grid should be filled in row-major order with consecutive integers starting from 1.
inputFormat
The first line contains an integer (T), the number of test cases. Each of the following (T) lines contains two space separated integers (R) and (C) representing the number of rows and columns of the grid.
outputFormat
For each test case, if the grid can be constructed, output the grid where each row is printed on a new line and the integers in the row are separated by a single space. If the grid cannot be constructed, output a single line with the word "Impossible". The outputs for different test cases are concatenated in order without additional separators.## sample
4
1 1
3 3
2 4
101 1
1
1 2 3
4 5 6
7 8 9
1 2 3 4
5 6 7 8
Impossible
</p>