// yukicoder: No.421 しろくろチョコレート // bal4u 2019.8.18 #include #include //// 入出力関係 #if 1 #define gc() getchar_unlocked() #else #define gc() getchar() #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0'); return n; } void ins(char *s) { // 文字列の入力 スペース以下の文字で入力終了 char *p = s; do *s = gc(); while (*s++ > ' '); *--s = 0; } //// 二部マッチング #define MAX 2502 int V; int hi[MAX], to[MAX][4]; char seen[MAX]; int match[MAX]; int bpm(int u); int bipartiteMatching(int m) { int u, max; memset(match, -1, sizeof(match)); max = 0; for (u = 0; u < m; u++) { memset(seen, 0, sizeof(seen)); if (bpm(u)) max++; } return max; } int bpm(int u) { int i, v; for (i = 0; i < hi[u]; i++) { v = to[u][i]; if (seen[v]) continue; seen[v] = 1; if (match[v] < 0 || bpm(match[v])) { match[u] = v, match[v] = u; return 1; } } return 0; } //// 本問題関連 int H, W; char map[53][53]; #define MIN(a,b) ((a)<=(b)?(a):(b)) #define rc2id(r, c) ((r)*W+(c)) int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}}; int main() { int i, r, c, t, rr, cc, tt, w, b, ans; H = in(), W = in(); w = b = 0; for (r = 0; r < H; r++) { ins(map[r]); for (c = 0; c < W; c++) { if (map[r][c] == 'w') w++; else if (map[r][c] == 'b') b++; } } if ((w | b) == 0) ans = 0; else if (w == 0 || b == 0) ans = w + b; else { for (r = 0; r < H; r++) for (c = r&1; c < W; c+=2) if (map[r][c] == 'w') { t = rc2id(r, c); for (i = 0; i < 4; i++) { rr = r+mv[i][0], cc = c+mv[i][1]; if (rr >= 0 && rr < H && cc >= 0 && cc < W && map[rr][cc] == 'b') to[t][hi[t]++] = rc2id(rr, cc); } } t = bipartiteMatching(H*W); w -= t, b -= t, ans = 100 * t; t = MIN(w, b), ans += 10 * t; w -= t, b -= t, ans += w + b; } printf("%d\n", ans); return 0; }