#P3392. 涂条纹
涂条纹
Description
As long as a flag composed of small squares meets the following rules, it is a valid pattern.
- All cells in the top several rows (at least one row) are white.
- The next several rows (at least one row) are blue.
- The remaining rows (at least one row) are red.
There is a cloth divided into rows and columns of cells, where each cell is one of white, blue, or red. Xiao A hopes to turn this cloth into a valid pattern by painting some cells to cover their previous colors.
Xiao A is lazy and wants to repaint the fewest cells so that the cloth becomes a valid pattern.
Input Format
The first line contains two integers .
Each of the next lines is a string of length , where each character is one of W (white), B (blue), or R (red).
Output Format
A single integer, the minimum number of cells that need to be repainted.
4 5
WRWRW
BWRWB
WRWRW
RWBWR
11
Hint
Sample Explanation
Target state is:
WWWWW
BBBBB
RRRRR
RRRRR
In total, cells need to be changed.
Constraints
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号