#K44257. Maximize Fully Grown Crops
Maximize Fully Grown Crops
Maximize Fully Grown Crops
You are given an 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 in the grid (with and ), 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 . Compute the total number of such cells in the reconfigured field.
inputFormat
The first line of input contains two integers and , representing the dimensions of the field. The following lines each contain a string of length , 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>