#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> E; int n, m; vector match, dist; void init(int _n,int _m){n=_n,m=_m;E.resize(n+m+2);match.resize(n+m+2);dist.resize(n+m+2);} bool bfs() { queue que; rep(i, 1, n + 1) { if (!match[i]) dist[i] = 0, que.push(i); else dist[i] = inf; } dist[0] = inf; while (!que.empty()) { int u = que.front(); que.pop(); if (u) fore(v, E[u]) if (dist[match[v]] == inf) { dist[match[v]] = dist[u] + 1; que.push(match[v]); } } return (dist[0] != inf); } bool dfs(int u) { if (u) { fore(v, E[u]) if (dist[match[v]] == dist[u] + 1) if (dfs(match[v])) { match[v] = u; match[u] = v; return true; } dist[u] = inf; return false; } return true; } void add(int a, int b) { b += n; E[a + 1].push_back(b + 1); E[b + 1].push_back(a + 1); } int whois(int x) { return match[x + 1] - 1; } int solve() { rep(i, 0, n + m + 1) match[i] = 0; int res = 0; while (bfs()) rep(i, 1, n + 1) if (!match[i] && dfs(i)) res++; return res; } }; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int H, W; string S[50]; int dx[4] = { 0, 1, 0, -1 }; int dy[4] = { -1, 0, 1, 0 }; //--------------------------------------------------------------------------------------------------- void _main() { cin >> H >> W; rep(i, 0, H) cin >> S[i]; vector b, w; rep(y, 0, H) rep(x, 0, W) { if (S[y][x] == 'b') b.push_back(y * W + x); if (S[y][x] == 'w') w.push_back(y * W + x); } sort(b.begin(), b.end()); sort(w.begin(), w.end()); BipartiteMatching bm; bm.init(b.size(), w.size()); rep(y, 0, H) rep(x, 0, W) if(S[y][x] == 'b'){ rep(i, 0, 4) { int xx = x + dx[i]; int yy = y + dy[i]; if (xx < 0 || W <= xx) continue; if (yy < 0 || H <= yy) continue; if (S[yy][xx] != 'w') continue; int bb = lower_bound(b.begin(), b.end(), y * W + x) - b.begin(); int ww = lower_bound(w.begin(), w.end(), yy * W + xx) - w.begin(); bm.add(bb, ww); } } int p100 = bm.solve(); int rb = b.size() - p100; int rw = w.size() - p100; int p10 = min(rb, rw); int ans = 100 * p100 + 10 * p10 + (b.size() - p100 - p10) + (w.size() - p100 - p10); cout << ans << endl; }