## DMOPC '21 Contest 6 P3 - An Art Problem

View as PDF

Points: 10 (partial)
Time limit: 3.0s
Memory limit: 1G

Author:
Problem type

Alice has just created an -pixel drawing on a digital art program. Each pixel can be coloured in one of different colours, numbered from to , or it can be blank, in which case it will be numbered with .

After Alice finished the drawing, she decided that it would look better if the edges of the drawing were expanded by pixels, maintaining colour. More specifically, let a step be a move of one pixel directly up, down, left, or right. If a blank pixel is or fewer steps away from a coloured pixel, it should take on the colour of that pixel. If multiple pixels are or fewer steps away, choose the colour of the closest one, and if multiple pixels are equally close, choose the lowest-numbered colour among them.

#### Input Specification

The first line contains three space-separated integers, , , and .
The next lines each contain space-separated integers: the colour of each pixel.

#### Output Specification

Output lines, each containing space-separated integers: the drawing after being expanded by pixels.

#### Sample Input

3 10 1
0 0 0 0 0 0 0 0 0 0
0 0 1 1 1 2 2 2 0 0
0 0 0 0 0 0 0 0 0 0

#### Sample Output

0 0 1 1 1 2 2 2 0 0
0 1 1 1 1 2 2 2 2 0
0 0 1 1 1 2 2 2 0 0