#P15756. [JAG 2025 Summer Camp #1] Chairs

[JAG 2025 Summer Camp #1] Chairs

题目描述

There are HWHW chairs arranged in HH rows and WW columns. We denote the chair in the ii-th row from the top and the jj-th column from the left by (i,j)(i, j).

Some chairs may have luggage placed on them. The situation of the chairs is represented by HH strings S1,S2,,SHS_1, S_2, \ldots, S_H, each of length WW. If the jj-th character of SiS_i is ‘#’, then there is luggage on (i,j)(i, j). If it is ‘.’, then there is no luggage on (i,j)(i, j). It is guaranteed that there is at least one chair on which there is no luggage.

We want to seat people on these chairs. At most one person can sit on each chair, and a person cannot sit on a chair that has luggage on it. Moreover, two people cannot sit on chairs that are adjacent to each other vertically or horizontally. Under these conditions, we want to seat as many people as possible. Let MM be the maximum number of people we can seat observing these rules.

Now, suppose one person arrives. For each chair, determine whether we may seat this person there. Specifically, determine whether it is possible to seat this person on that chair, and in addition, still be able to seat M1M - 1 more people under the rules.

输入格式

The input is given in the following format:

$$\begin{aligned} &H \ W \\ &S_1 \\ &S_2 \\ &\vdots \\ &S_H \end{aligned} $$
  • 1H4001 \leq H \leq 400
  • 1W4001 \leq W \leq 400
  • SiS_i is a string of length WW consisting of ‘#’ and ‘.’ (1iH1 \leq i \leq H).
  • There exists (i,j)(i, j) such that the jj-th character of SiS_i is ‘.’.
  • HH and WW are integers.

输出格式

Output HH lines. On the ii-th line (1iH1 \leq i \leq H), output a string of length WW.

For each (i,j)(i, j), if we can seat the newly arrived person on (i,j)(i, j), then the jj-th character of the string on the ii-th line must be ‘1’. Otherwise, it must be ‘0’.

3 4
##..
....
#.##
0011
1011
0100