Legendary Dango Maker 6
Time limit1sMemory limit512 MB
Given a grid of P, W, and G dango, find the maximum number of disjoint sticks where a W sits between opposite P and G, and mark each stick's middle cell by direction.
Problem
You are a professional rice dumpling maker. Now you are skewering dangos onto sticks.
Dangos are arranged in a rectangular grid of R rows and C columns. Each cell contains one dango. The color of a dango is pink (P), white (W), or green (G). You choose three consecutive dangos in the vertical direction, the horizontal direction, or one of the two diagonal directions (left-top to right-bottom, or right-top to left-bottom). Then you take the three dangos from end to end and skewer them onto a stick in order. This forms a stick of dangos. For example, if you choose three consecutive dangos vertically, you can take them top-middle-bottom or bottom-middle-top, in that order. You cannot take them middle-bottom-top or bottom-top-middle. You cannot skewer a dango onto more than one stick.
A stick of dangos is beautiful if its colors, in order, are pink-white-green or green-white-pink. How many beautiful sticks of dangos can you make?
Input
The input is given in the following format.
R C
D1
.
.
.
DR
Di (1 <= i <= R) is a string of length C consisting of P, W, and G. The j-th character of Di is the color of the dango in the cell located in the i-th row from the top and the j-th column from the left.
Output
Print R lines S1 to SR, each a string of length C. The j-th character of Si describes the cell in the i-th row and j-th column:
|if that cell is the middle of a beautiful stick taken with the cells directly above and below it.-if that cell is the middle of a beautiful stick taken with the cells directly left and right of it.\if that cell is the middle of a beautiful stick taken with the cells left-above and right-below it./if that cell is the middle of a beautiful stick taken with the cells right-above and left-below it.- Otherwise, the color character P, W, or G, the same as the j-th character of Di.
Constraints
3 <= R <= 500. 3 <= C <= 500. Di (1 <= i <= R) is a string of length C consisting of P, W, and G.