Tiles P82243


Statement
 

pdf   zip

You have nmn \cdot 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×mn \times 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 nn and mm, followed by nmn \cdot m numbers, all between 1 and nmn \cdot m. Assume 1nm1051 \le n \cdot m \le 10^5.

Output

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

Public test cases
  • Input

    2 3
    6 1 1 4 4 6
    2 3
    6 1 1 4 4 6
    2 3
    6 6 6 6 2 2
    4 4
    1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
    1 11
    1 2 3 4 5 6 7 8 9 10 11
    

    Output

    YES
    1 4 6
    6 1 4
    YES
    6 4 1
    4 1 6
    NO
    YES
    4 3 2 1
    3 1 4 3
    1 2 3 1
    2 4 2 4
    YES
    5 11 4 6 3 7 2 8 10 9 1
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++