#P9767. Matrix Coloring Without Uniform Rectangle Corners

    ID: 22913 Type: Default 1000ms 256MiB

Matrix Coloring Without Uniform Rectangle Corners

Matrix Coloring Without Uniform Rectangle Corners

We are given an (n \times m) matrix and (c) available colors (numbered 1 through (c)). Your task is to color the matrix so that for any rectangle defined by indices (1 \le x_1 < x_2 \le n) and (1 \le y_1 < y_2 \le m), the colors at the four corners ((x_1,y_1)), ((x_1,y_2)), ((x_2,y_1)) and ((x_2,y_2)) are not all identical. In other words, it must not be the case that [ \text{color}(x_1,y_1)=\text{color}(x_1,y_2)=\text{color}(x_2,y_1)=\text{color}(x_2,y_2). ] It is guaranteed that a valid coloring scheme exists.

Hint: When (n>1) and (m>1) (so that a rectangle exists), a simple alternating (chessboard) pattern is sufficient. In cases where either (n=1) or (m=1), there is no rectangle, so any coloring (for example, filling with color 1) is acceptable.

inputFormat

The input consists of three integers (n), (m), and (c) on one line, where (n) and (m) represent the dimensions of the matrix, and (c) represents the number of available colors. It is guaranteed that the input parameters allow at least one valid solution.

outputFormat

Output (n) lines, each containing (m) integers. The (j)-th integer in the (i)-th line indicates the color assigned to cell ((i,j)). The colors should be integers between 1 and (c).

sample

1 5 5
1 1 1 1 1