#include<bits/stdc++.h> #include<atcoder/all> usingnamespace std; usingnamespace atcoder; #ifdef LOCAL #define debug(...) fprintf(stdout, ##__VA_ARGS__) #else #define debug(...) void(0) #endif //#define int long long inlineintread(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back #define fi first #define se second //#define M //#define mo #define N 35 int n, m, i, j, k, T; int ans, S; char s[N][N];
signedmain(){ #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // srand(time(NULL)); // T = read(); // while(T--) { // // } n = read(); m = read(); mf_graph<int>G(n * m + 2); S = 0; T = n * m + 1; for(i = 1; i <= n; ++i) scanf("%s", s[i] + 1); auto zh = [&] (int x, int y) -> int { return (x - 1) * m + y; }; for(i = 1; i <= n; ++i) for(j = 1; j <= m; ++j) { if(s[i][j] == '#') continue; if(s[i][j] == '+') ++ans; if(s[i][j] == '+') G.add_edge(S, zh(i, j), 1); if(s[i][j] == '-') G.add_edge(zh(i, j), T, 1); if(j < m && s[i][j + 1] != '#') { G.add_edge(zh(i, j), zh(i, j + 1), 1e9); G.add_edge(zh(i, j + 1), zh(i, j), 1e9); } if(i > 1 && s[i - 1][j] != '#') { G.add_edge(zh(i, j), zh(i - 1, j), 1e9); } } ans -= G.flow(S, T); printf("%d", ans); return0; }