#P3936. Coloring

    ID: 2876 远端评测题 5000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>搜索洛谷原创Special Judge模拟退火

Coloring

Description

Snakes\text{Snakes} is playing a game where he colors squares on a white paper with n×mn\times m grid cells. However, messy coloring is not fun, so he came up with a peculiar problem:

In an n×mn\times m grid, use cc different colors to try to color all cells. Different colors are represented by integers in 1...c1...c. The coloring must satisfy the following conditions:

  • Each cell must be colored in exactly one color.

  • Color ii must color exactly pip_i cells. It is guaranteed that i=1cpi=n×m\sum_{i=1}^c p_i = n\times m.

  • Consider cells that are adjacent up, down, left, or right and have the same color to be in the same connected component, and define qq as the number of grid edges between different connected components. See the sample explanation.

Now, Snakes\text{Snakes} wants to know, given nn, mm, cc and p1...pcp_1...p_c, whether you can construct a valid coloring that makes qq as small as possible.

Input Format

The first line contains three numbers, n,m,cn,m,c.

The second line contains cc numbers, where the ii-th number is pip_i.

Output Format

Output nn lines, each containing mm numbers, representing your constructed n×mn\times m coloring with qq as small as possible.

2 3 3
1 2 3
2 3 1
2 3 3

Hint

   |   |   
 2 | 3 | 1 
   +   +---
 2 | 3   3 
   |       

For the sample, q=4q=4, consisting of three vertical edges and one horizontal edge.

Conventions

This problem is Special Judge.

For each test point, a threshold ww is set, and it is guaranteed that there exists a construction such that qwq\leq w.

The score for your output will be computed as follows:

$$\begin{matrix}q&score&q&score\\\\ q \leq w&10&1.75w < q \leq 2w&5\\\\ w < q \leq 1.1w&9&2w < q \leq 2.3w&4\\\\ 1.1w < q \leq 1.25w&8&2.3w < q \leq 2.6w&3\\\\ 1.25w < q \leq 1.5w&7&2.6w < q \leq 3w&2\\\\ 1.5w < q \leq 1.75w&6&3w < q \leq 3.5w&1\end{matrix}$$

If q>3.5wq > 3.5w, it will be judged as Wrong Answer.

The score shown during the contest is the final score.

Constraints

For 10%10\% of the testdata, 1n,m31\leq n,m\leq 3, c3c\leq 3.

For 30%30\% of the testdata, 1n,m81\leq n,m\leq 8, c6c\leq 6.

For 50%50\% of the testdata, 1n,m151\leq n,m\leq 15, c25c\leq 25.

For 100%100\% of the testdata, 1n,m201\leq n,m\leq 20, c50c\leq 50, pi20p_i\leq 20.

Translated by ChatGPT 5