酋长试炼AI (CI翻译)
Having unraveled the Berland Dictionary, the scientists managed to read the notes of the chroniclers of that time. For example, they learned how the chief of the ancient Berland tribe was chosen.
As soon as enough pretenders was picked, the following test took place among them: the chief of the tribe took a slab divided by horizontal and vertical stripes into identical squares (the slab consisted of $*N*$ lines and $*M*$ columns) and painted every square black or white. Then every pretender was given a slab of the same size but painted entirely white. Within a day a pretender could paint any side-linked set of the squares of the slab some color. The set is called linked if for any two squares belonging to the set there is a path belonging the set on which any two neighboring squares share a side. The aim of each pretender is to paint his slab in the exactly the same way as the chief’s slab is painted. The one who paints a slab like that first becomes the new chief.
Scientists found the slab painted by the ancient Berland tribe chief. Help them to determine the minimal amount of days needed to find a new chief if he had to paint his slab in the given way.
Input
输入格式
AI (CI翻译)The first line contains two integers $*N*$ and $*M*$ ($1 ≤ *N*, *M* ≤ 50$) — the number of lines and columns on the slab. The next $*N*$ lines contain $*M*$ symbols each — the final coloration of the slab. $*W*$ stands for the square that should be painted white and $*B*$ — for the square that should be painted black.
第一行包含两个整数 $*N*$ 和 $*M*$($1 ≤ *N*, *M* ≤ 50$),分别表示木板的行数和列数。接下来的 $*N*$ 行每行包含 $*M*$ 个字符,表示木板的最终涂色。$*W*$ 表示应涂成白色的正方形,$*B*$ 表示应涂成黑色的正方形。AI (CI翻译)
Output
输出格式
AI (CI翻译)In the single line output the minimal number of repaintings of side-linked areas needed to get the required coloration of the slab.
在单独一行中输出得到所需木板涂色所需的最少相连区域重涂次数。 AI (CI翻译)
样例
3 3
WBW
BWB
WBW
2
2 3
BBB
BWB
1
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。