#include <bits/stdc++.h>
using namespace std;
char mat[1005][15];
int main(){
int n, m; cin >> n >> m;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> mat[i][j];
vector <int> dp(1 << m, 1e8), ndp(1 << m);
dp[0] = 0;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
for(int k = 0; k < (1 << m); k++) ndp[k] = (k & (1 << j) ? (mat[i][j] == '.' ? 1e8 : min(dp[k], dp[k ^ (1 << j)] + 1)) : min(dp[k], dp[k ^ (1 << j)]) + (mat[i][j] == '#' && (j == 0 || (k & (1 << (j - 1))) || mat[i][j - 1] == '.')));
dp = ndp;
}
cout << *min_element(dp.begin(), dp.end()) << " ";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |