#K44257. Maximize Fully Grown Crops

    ID: 27491 Type: Default 1000ms 256MiB

Maximize Fully Grown Crops

Maximize Fully Grown Crops

You are given an M×NM\times N field. You have the option to completely replant the field such that every cell contains a crop, denoted by the character 'C'. A crop is considered fully grown if it has exactly three adjacent crops. The adjacent cells are those directly to the north, south, east, and west of a cell. Note that cells on the boundaries of the field have fewer than four neighbors. Your task is to determine the maximum number of fully grown crops that can be achieved when the field is entirely replanted with crops.

Formally, for a cell at position (i,j)(i,j) in the grid (with 0i<M0 \le i < M and 0j<N0 \le j < N), let its number of valid adjacent neighbors be defined as: [ \text{adj}(i,j) = \begin{cases} \text{(if valid)}\end{cases} ] Since the field is completely filled with crops, a cell is fully grown if the number of its adjacent neighbors equals 33. Compute the total number of such cells in the reconfigured field.

inputFormat

The first line of input contains two integers MM and NN, representing the dimensions of the field. The following MM lines each contain a string of length NN, representing the initial configuration of the field; however, this initial configuration is ignored since the field will be entirely replanted.

outputFormat

Output a single integer representing the maximum number of fully grown crops in the field after replanting.## sample

3 3
C.C
.C.
C.C
4

</p>