#P9271. Maximum Non‑Blocked Parking Arrangement
Maximum Non‑Blocked Parking Arrangement
Maximum Non‑Blocked Parking Arrangement
The parking lot operator wants to use an arrangement so that no parked car is blocked. You are given a parking lot layout in the form of an n×m grid. Some cells may already have a parked car (denoted by C
) and cannot be moved. An empty cell is denoted by .
.
A car is considered non‑blocked if either it is located on the boundary of the grid or, if it is in an interior cell, then at least one of its 4 adjacent cells (up, down, left, right) is empty. In other words, for every car located at an interior cell with coordinates i and j (with 1≤i≤n−2 and 1≤j≤m−2), the following condition must hold:
[ \exists,(dx,dy) \in {(-1,0),(1,0),(0,-1),(0,1)} \quad \text{such that cell } (i+dx, j+dy) \text{ is empty.} ]
Your task is to add as many cars as possible (without moving or removing already parked cars) so that none of the cars (both pre‐parked and newly added) is blocked. Then output the maximum total number of cars along with one valid arrangement that attains this maximum.
inputFormat
The first line contains two integers n
and m
(the number of rows and columns of the grid). The next n
lines each contain a string of length m
composed of characters \'.\'
(empty cell) and \'C\'
(a cell with an already parked car). It is guaranteed that the initial configuration is safe (i.e. no already parked car is blocked).
outputFormat
Output the maximum number of cars that can be parked (including the ones already there) in the first line. Then, output n
lines representing the final parking arrangement. In the arrangement, a parked car is represented by C
and an empty slot by .
. Note that a car on the boundary is automatically non‐blocked, and an interior car must have at least one adjacent cell (up, down, left or right) that is empty.
sample
3 3
...
...
...
8
CCC
C.C
CCC
</p>