#P7668. [JOI 2018 Final] 团子制作 / Dango Maker
[JOI 2018 Final] 团子制作 / Dango Maker
Description
The dumplings are placed on a grid of cells with rows and columns. Each cell contains one dumpling. The color of each dumpling is red (), green (), or white ().
You will choose three consecutive dumplings from the cells and skewer them onto one stick. The direction of the chosen three consecutive dumplings must be left to right, or top to bottom.
Now, you want to make dango sticks whose colors, in this order, are red, green, and white. You want to make as many dango sticks as possible. The order of dumplings on the stick must be the same as the order of the dumplings selected from the cells. A dumpling cannot be used on more than one stick.
Given the colors of the dumplings placed on the grid, write a program to compute the maximum number of dango sticks you can make. The colors must be red, green, white in this order.
Input Format
The first line of input contains two space-separated integers and . Each of the next lines contains a string of length , consisting of , , or . The -th character of this string is the color of the dumpling in the -th row from the top and the -th column from the left.
Output Format
Print one integer: the maximum number of dango sticks.
3 4
RGWR
GRGG
RGWW
3
4 4
RGWR
GRRG
WGGW
WWWR
4
Hint
Constraints
For of the testdata, , , , .
- Subtask ( points): , .
- Subtask ( points): , .
- Subtask ( points): no additional constraints.
Sample Explanation
For Sample : You can make dango sticks.
- You choose three consecutive dumplings starting at the first row from the top and the first column from the left. The direction is left to right. Then you skewer them in this order.
- You choose three consecutive dumplings starting at the first row from the top and the -th column from the left. The direction is top to bottom. Then you skewer them in this order.
- You choose three consecutive dumplings starting at the third row from the top and the first column from the left. The direction is left to right. Then you skewer them in this order.
Since you cannot make sticks, the output is .
For Sample : You can make dango sticks.
- You choose three consecutive dumplings starting at the first row from the top and the first column from the left. The direction is left to right. Then you skewer them in this order.
- You choose three consecutive dumplings starting at the first row from the top and the -th column from the left. The direction is top to bottom. Then you skewer them in this order.
- You choose three consecutive dumplings starting at the second row from the top and the second column from the left. The direction is top to bottom. Then you skewer them in this order.
- You choose three consecutive dumplings starting at the second row from the top and the third column from the left. The direction is top to bottom. Then you skewer them in this order.
Since you cannot make sticks, the output is .
Problem Note
This problem comes from T3: Dango Maker of The 17th Japanese Olympiad in Informatics (JOI 2017/2018) Final Round: T3: Dango Maker.
Translated and整理 (pinyin: zhengli, compiled/organized) by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号