#K77912. Paint the Canvas
Paint the Canvas
Paint the Canvas
You are given a canvas of n rows and m columns, and k colors numbered from 1 to k. The task is to fill the canvas with colors such that the following constraints are satisfied for every cell:
- No cell in the p cells directly above (if any) has the same color.
- No cell in the q cells immediately to the left (if any) has the same color.
- No cell in the r cells diagonally top-left (if any) has the same color.
Determine whether there exists a valid way to paint the entire canvas following these rules. If such a valid coloring exists, output YES
followed by the canvas configuration. Otherwise, output NO
.
Note: If there are multiple valid solutions, outputting any one of them is acceptable. All formulas in this statement are provided in LaTeX format. For example, the constraints are as follows:
\( \text{Above constraint: For cell } (i,j), \; \forall t \in \{1,2,\ldots,p\}, \; \text{if } i-t \ge 0 \text{ then } canvas[i-t][j] \neq canvas[i][j] \).
\( \text{Left constraint: For cell } (i,j), \; \forall t \in \{1,2,\ldots,q\}, \; \text{if } j-t \ge 0 \text{ then } canvas[i][j-t] \neq canvas[i][j] \).
\( \text{Diagonal constraint: For cell } (i,j), \; \forall t \in \{1,2,\ldots,r\}, \; \text{if } i-t \ge 0 \text{ and } j-t \ge 0 \text{ then } canvas[i-t][j-t] \neq canvas[i][j] \).
inputFormat
The input consists of a single line containing six space-separated integers: n, m, k, p, q, and r.
- n: Number of rows of the canvas.
- m: Number of columns of the canvas.
- k: Total number of colors available (colors are labeled 1 through k).
- p: The number of cells above to check for color conflicts.
- q: The number of cells to the left to check for color conflicts.
- r: The number of cells in the top-left diagonal to check for color conflicts.
outputFormat
If a valid painting exists, output should consist of:
- A first line with the string "YES".
- n subsequent lines where each line contains m space-separated integers representing the colors of the canvas row.
3 3 3 2 2 1
YES
1 2 3
2 3 1
3 1 2
</p>