Skewers
InterviewTime limit1sMemory limit1024 MB
Given a grid of meat, scallion, and mushroom cells, find the most skewers that each take one adjacent meat and scallion in a line with a mushroom at one end.
Problem
Sejong is threading ingredients onto skewers to roast over a campfire during a camping trip. His mother asked him to put one meat, one scallion, and one mushroom on each skewer so the family eats a balanced mix. Sejong dislikes mushrooms, so he wants skewers with only meat and scallion. He plans to thread one meat and one scallion, then pretend to add a mushroom at the end and roast the skewer without actually adding one.
The ingredients are laid out in an grid. Each cell holds meat, scallion, or mushroom. To make a skewer, choose three cells in a row, column, or diagonal that are consecutive, and thread the ingredients in that order. The mushroom must be at an end of the skewer, because it is only a pretend addition. A meat or scallion cell cannot go onto more than one skewer, but one mushroom can be used for several skewers.
Input
The first line contains two integers and , separated by a space.
From the second line onward, lines each contain a string of length . The -th character of the -th string is the ingredient in row , column . Each string consists only of S, G, and M, which stand for meat, scallion, and mushroom.
Output
Print the maximum number of mushroom-free skewers Sejong can make.