#P7668. Dumpling Stick Formation
Dumpling Stick Formation
Dumpling Stick Formation
Dumplings are arranged in a grid with \(N\) rows and \(M\) columns, where each cell contains exactly one dumpling. Each dumpling is colored red (\(R\)), green (\(G\)), or white (\(W\)).
You are allowed to select three consecutive dumplings from the grid and skewer them on a stick. The three dumplings must be selected in order either horizontally (from left to right) or vertically (from top to bottom). The dumplings on the stick must have the colors red, green, white in that order. Each dumpling can be used at most once.
Your task is to determine the maximum number of dumpling sticks you can form following these rules.
Note: If a candidate triple of cells meets the color order \(R, G, W\) and the cells are adjacent in either a row or a column, you may choose them. However, the same cell cannot be used in more than one triple.
inputFormat
The first line contains two integers \(N\) and \(M\) (the number of rows and columns respectively). Each of the next \(N\) lines contains a string of length \(M\) consisting only of the characters R
, G
, and W
, representing the color of the dumpling in that cell.
outputFormat
Output a single integer representing the maximum number of dumpling sticks that can be formed.
sample
3 3
RGW
RGW
RGW
3
</p>