P2102 Floor Tiling
Description
After making a big profit at the arcade, Xiao Z finally won the furniture he wanted. Taking this opportunity, he wants to tidy up his room.
At the department store, you can buy square floor tiles in various colors. For the sake of aesthetics, Xiao Z does not want square tiles of the same color to be adjacent. So he asked Xiao C to help solve this.
Xiao C quickly solved the task. However, due to a kind of OCD, she wants the sequence of colors of all cells, when the floor is divided into a grid by length and width and read row by row and column by column, to be lexicographically smallest. She hopes you can help verify her plan.
Input Format
The first line contains two integers $N$ and $M$, representing the length and the width of the room.
Output Format
Output $N$ lines, each with $M$ columns, representing a tiling plan. The plan must be the lexicographically smallest among all valid plans. (You may regard that the concatenated string formed by removing newlines from the output plan is lexicographically smallest.)
Explanation/Hint
Constraints:
- For $50\%$ of the testdata, it is guaranteed that $N, M \leq 5$.
- For $100\%$ of the testdata, it is guaranteed that $1 \leq N, M \leq 100$.
Translated by ChatGPT 5