No.421 Black and White Chocolate
タグ : / 解いたユーザー数 173
作問者 :
koyumeishi
/ テスター :
37zigen
Problem Statement
"Black and White Chocolate", a chocolate confection manufactured and sold by Yuki Confectionery, is a treat loved by everyone. Black and White Chocolate is a chocolate bar consisting of $N$×$M$ blocks, but it is a little different from an ordinary chocolate bar. Black bitter chocolate and white chocolate alternate block by block, making it a beautiful-looking confection, just like a chessboard.
Chiyoko loves this chocolate, and she can gain happiness by eating it in any of the following ways.
-
Method 1
Cut out a block of size $1×1$ from any position of the chocolate bar and eat it.
The happiness gained in this case is $1$.
-
Method 2
Cut out a white chocolate block and a bitter chocolate block from any positions of the chocolate bar, each of size $1×1$, and eat them at the same time.
The happiness gained in this case is $10$.
-
Method 3
Cut out a piece of size $2×1$ (or $1×2$) in which a white chocolate block and a bitter chocolate block are contiguous from any position of the chocolate bar , and eat it.
The happiness gained in this case is $100$.
Since Chiyoko can cut out blocks from any position, she does not need to cut them out in order starting from the edge.
However, because it would spoil the flavor, pieces that have once been cut cannot be melted and rejoined.
Also, eating the chocolate in any way other than these gives no happiness.
Chiyoko bought a Black and White Chocolate as a reward for herself.
She planned to eat all of it by herself,
but it seems her younger brother Reito has snacked on part of it.
Given the state of the chocolate after Reito snacked on it,
find the maximum happiness Chiyoko can gain from the remaining chocolate.
Input
The first line gives the number of blocks in the vertical direction $N$ and the number of blocks in the horizontal direction $M$ of the chocolate at the time of purchase.
Each of the following N lines gives the state of the $i$-th row of the chocolate as a string $S_i$ of length $M$.
If $S_{i,j}$ is 'w', block [$i,j$] is white chocolate.
If $S_{i,j}$ is 'b', block [$i,j$] is bitter chocolate.
If $S_{i,j}$ is '.', the chocolate of block [$i,j$] has already been eaten by Reito.
$N$ $M$ $S_1$ $S_2$ $\vdots$ $S_N$
The input satisfies the following constraints.
$N$ and $M$ are integers
$1 \leq N,M \leq 50$
$|S_i| = M$
When $i+j$ is even, $S_{i,j} = $ 'w' or '.'
When $i+j$ is odd, $S_{i,j} = $'b' or '.'
Output
Print on one line the maximum happiness Chiyoko can gain. Print a newline at the end.
Sample
Sample 1
Input
2 3 wbw bw.
Output
201
Cutting out and eating two $2×1$ pieces and one $1×1$ block gives happiness 201.
Sample 2
Input
3 4 wb.. b..w ..wb
Output
210
The chocolate may not be connected.
For example, cutting it out as follows gives happiness 210.
Sample 3
Input
4 4 wbwb b... wbwb ...w
Output
500
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。