from collections import deque class Dinic: def __init__(self, n, INF=float('inf')): self.n = n self.INF = INF self.pos = [] self.G = [[] for _ in range(n)] self.level = None self.iters = None def add_edge(self, fr, to, cap): self.pos.append((fr, len(self.G[fr]))) self.G[fr].append([cap, to, len(self.G[to])]) self.G[to].append([0, fr, len(self.G[fr])-1]) def bfs(self, s): level = [-1]*self.n level[s] = 0 q = deque([s]) while q: v = q.popleft() for cap, to, rev in self.G[v]: if cap > 0 and level[to] < 0: level[to] = level[v]+1 q.append(to) self.level = level def dfs(self, v, t, flow): if v == t: return flow for i in range(self.iters[v], len(self.G[v])): self.iters[v] = i cap, to, rev = self.G[v][i] if cap > 0 and self.level[v] < self.level[to]: d = self.dfs(to, t, min(flow, cap)) if d > 0: self.G[v][i][0] -= d self.G[to][rev][0] += d return d return 0 def max_flow(self, s, t): flow = 0 while True: self.bfs(s) if self.level[t] < 0: return flow self.iters = [0]*self.n f = self.dfs(s, t, self.INF) while f > 0: flow += f f = self.dfs(s, t, self.INF) n, m = map(int, input().split()) S = [input() for i in range(n)] INF = 10**9 dinic = Dinic(n*m+2, INF) w, b = 0, 0 s = n*m t = n*m+1 for i in range(n): for j in range(m): if (i+j)%2 == 0 and S[i][j] != '.': w += 1 dinic.add_edge(s, i*m+j, 1) # source > even if (i+j)%2 == 1 and S[i][j] != '.': b += 1 dinic.add_edge(i*m+j, t, 1) # odd > sink for i, row in enumerate(S): for j, c in enumerate(row): v = i*m+j if c == '.' or (i+j)%2 == 1: continue for di, dj in (-1, 0), (1, 0), (0, -1), (0, 1): ni, nj = i+di, j+dj if 0 <= ni < n and 0 <= nj < m: u = ni*m+nj if S[ni][nj] != '.': dinic.add_edge(v, u, 1) # even > odd f = dinic.max_flow(s, t) ans = 0 ans += f*100 w -= f b -= f ans += 10*min(w, b)+(max(w, b)-min(w,b)) print(ans)