#C1931. Enchanted Grid Transformation
Enchanted Grid Transformation
Enchanted Grid Transformation
In this problem, you are given a grid of characters where each cell can be either a dragon ('D') or a phoenix ('P'). The grid undergoes a magical enchantment process: simultaneously, for every cell containing a dragon, if it has at least one phoenix in any of its eight neighboring cells (adjacent horizontally, vertically, or diagonally), then that dragon transforms into a phoenix. Cells containing a phoenix remain unchanged.
The transformation is applied only once based on the initial state of the grid. Your task is to determine the final state of the grid after this enchantment process.
Note: The neighbors of a cell (r, c) are the cells at positions (r + dr, c + dc) for dr,dc ∈ \{-1, 0, 1\} where (dr, dc) ≠ (0, 0) and within grid bounds.
inputFormat
The first line contains two space-separated integers R and C (representing the number of rows and columns respectively).
The following R lines each contain a string of length C representing the rows of the grid, where each character is either 'D' or 'P'.
outputFormat
Output R lines, each line containing a string of length C representing the final state of the grid after the transformation.
## sample3 3
DDD
DPD
DDD
PPP
PPP
PPP
</p>