#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int dp[1000][10][1 << 10][2];
bool a[1000][10];
int n, m;
int checkbit (int mask, int x) {
return (mask >> x) & 1;
}
int off (int mask, int x) {
if (checkbit(mask, x)) mask ^= 1 << x;
return mask;
}
int ans (int pos, int cur, int mask, int c) {
if (pos == n) return 0;
if (cur == m) {
return ans(pos + 1, 0, mask, 0);
}
if (a[pos][cur] == 0) {
return ans(pos, cur + 1, off(mask, cur), 0);
}
int &ret = dp[pos][cur][mask][c];
if (ret != -1) return ret;
ret = inf;
if (checkbit(mask, cur)) {
ret = min(ret, ans(pos, cur + 1, mask, 0));
} else {
ret = min(ret, 1 + ans(pos, cur + 1, mask ^ (1 << cur), 0));
}
if (c) {
ret = min(ret, ans(pos, cur + 1, off(mask, cur), 1));
} else {
ret = min(ret, 1 + ans(pos, cur + 1, off(mask, cur), 1));
}
return ret;
}
int main () {
memset(dp, -1, sizeof(dp));
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char c;
cin >> c;
a[i][j] = c == '#';
}
}
cout << ans(0, 0, 0, 0) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
80476 KB |
Output is correct |
2 |
Correct |
12 ms |
80728 KB |
Output is correct |
3 |
Correct |
13 ms |
80668 KB |
Output is correct |
4 |
Correct |
12 ms |
80732 KB |
Output is correct |
5 |
Correct |
13 ms |
80760 KB |
Output is correct |
6 |
Correct |
14 ms |
80732 KB |
Output is correct |
7 |
Correct |
14 ms |
80988 KB |
Output is correct |
8 |
Correct |
11 ms |
80564 KB |
Output is correct |
9 |
Correct |
12 ms |
80732 KB |
Output is correct |
10 |
Correct |
37 ms |
81096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
80476 KB |
Output is correct |
2 |
Correct |
10 ms |
80476 KB |
Output is correct |
3 |
Correct |
9 ms |
80476 KB |
Output is correct |
4 |
Correct |
10 ms |
80476 KB |
Output is correct |
5 |
Correct |
10 ms |
80476 KB |
Output is correct |
6 |
Correct |
10 ms |
80476 KB |
Output is correct |
7 |
Correct |
10 ms |
80600 KB |
Output is correct |
8 |
Correct |
10 ms |
80476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
80476 KB |
Output is correct |
2 |
Correct |
12 ms |
80728 KB |
Output is correct |
3 |
Correct |
13 ms |
80668 KB |
Output is correct |
4 |
Correct |
12 ms |
80732 KB |
Output is correct |
5 |
Correct |
13 ms |
80760 KB |
Output is correct |
6 |
Correct |
14 ms |
80732 KB |
Output is correct |
7 |
Correct |
14 ms |
80988 KB |
Output is correct |
8 |
Correct |
11 ms |
80564 KB |
Output is correct |
9 |
Correct |
12 ms |
80732 KB |
Output is correct |
10 |
Correct |
37 ms |
81096 KB |
Output is correct |
11 |
Correct |
10 ms |
80476 KB |
Output is correct |
12 |
Correct |
10 ms |
80476 KB |
Output is correct |
13 |
Correct |
9 ms |
80476 KB |
Output is correct |
14 |
Correct |
10 ms |
80476 KB |
Output is correct |
15 |
Correct |
10 ms |
80476 KB |
Output is correct |
16 |
Correct |
10 ms |
80476 KB |
Output is correct |
17 |
Correct |
10 ms |
80600 KB |
Output is correct |
18 |
Correct |
10 ms |
80476 KB |
Output is correct |
19 |
Correct |
11 ms |
80856 KB |
Output is correct |
20 |
Correct |
15 ms |
80984 KB |
Output is correct |
21 |
Correct |
16 ms |
80984 KB |
Output is correct |
22 |
Correct |
10 ms |
80476 KB |
Output is correct |
23 |
Correct |
11 ms |
80476 KB |
Output is correct |
24 |
Correct |
12 ms |
80640 KB |
Output is correct |
25 |
Correct |
22 ms |
80988 KB |
Output is correct |
26 |
Correct |
45 ms |
81244 KB |
Output is correct |
27 |
Correct |
86 ms |
81500 KB |
Output is correct |
28 |
Correct |
132 ms |
81500 KB |
Output is correct |