Tiles

You have n ⋅ m square tiles, each painted with a color codified with a
number. You will have to use the tiles to cover a floor of dimensions
n × m, with just one restriction: there cannot be two or more
(horizontal or vertical) adjacent tiles of the same color. Can you find
a solution?

Input

Input consists of several cases, each with n and m, followed by n ⋅ m
numbers, all between 1 and n ⋅ m. Assume 1 ≤ n ⋅ m ≤ 10⁵.

Output

For each case, if there is no solution, print a line with “NO”.
Otherwise, print a line with “YES”, followed by n lines with m numbers
each. If there is more than one solution, you can print any one. Follow
strictly the format of the sample output.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:56:42.604Z

© Jutge.org, 2006–2026.
https://jutge.org
