#include<bits/stdc++.h>
using namespace std;
int l, c, dp[1005][15][1029], aux;
char m[1005][15];
int solve(int i, int j, int mask) {
int &ans = dp[i][j][mask];
if(ans != -1)
return ans;
if(j == c)
return solve(i+1, 0, mask);
if(i == l)
return 0;
int kek = 1<<j;
if(m[i][j] == '.')
return ans = solve(i, j+1, mask & (aux - kek));
ans = min( solve(i, j+1, mask | kek) , solve(i, j+1, mask & (aux - kek)) ) + 1;
if(i) {
int now = ( mask & (1<<j) );
if(now && m[i-1][j] == '#')
ans = min(ans, solve(i, j+1, mask | kek));
}
if(j) {
int now = mask & (1<<(j-1));
if(!now && m[i][j-1] == '#')
ans = min(ans, solve(i, j+1, mask & (aux - kek)));
}
return ans;
}
int32_t main() {
cin >> l >> c;
aux = (1<<c)-1;
memset(dp, -1, sizeof dp);
for(int i = 0; i < l; i++)
for(int j = 0; j < c; j++)
cin >> m[i][j];
cout << solve(0, 0, 0) << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
61120 KB |
Output is correct |
2 |
Correct |
31 ms |
61952 KB |
Output is correct |
3 |
Correct |
30 ms |
61764 KB |
Output is correct |
4 |
Correct |
31 ms |
61840 KB |
Output is correct |
5 |
Correct |
33 ms |
62028 KB |
Output is correct |
6 |
Correct |
35 ms |
62004 KB |
Output is correct |
7 |
Correct |
34 ms |
62028 KB |
Output is correct |
8 |
Correct |
29 ms |
61980 KB |
Output is correct |
9 |
Correct |
32 ms |
62004 KB |
Output is correct |
10 |
Correct |
66 ms |
62040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
60972 KB |
Output is correct |
2 |
Correct |
28 ms |
60904 KB |
Output is correct |
3 |
Correct |
27 ms |
61016 KB |
Output is correct |
4 |
Correct |
28 ms |
60996 KB |
Output is correct |
5 |
Correct |
26 ms |
60924 KB |
Output is correct |
6 |
Correct |
27 ms |
60996 KB |
Output is correct |
7 |
Correct |
27 ms |
61004 KB |
Output is correct |
8 |
Correct |
31 ms |
61020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
61120 KB |
Output is correct |
2 |
Correct |
31 ms |
61952 KB |
Output is correct |
3 |
Correct |
30 ms |
61764 KB |
Output is correct |
4 |
Correct |
31 ms |
61840 KB |
Output is correct |
5 |
Correct |
33 ms |
62028 KB |
Output is correct |
6 |
Correct |
35 ms |
62004 KB |
Output is correct |
7 |
Correct |
34 ms |
62028 KB |
Output is correct |
8 |
Correct |
29 ms |
61980 KB |
Output is correct |
9 |
Correct |
32 ms |
62004 KB |
Output is correct |
10 |
Correct |
66 ms |
62040 KB |
Output is correct |
11 |
Correct |
29 ms |
60972 KB |
Output is correct |
12 |
Correct |
28 ms |
60904 KB |
Output is correct |
13 |
Correct |
27 ms |
61016 KB |
Output is correct |
14 |
Correct |
28 ms |
60996 KB |
Output is correct |
15 |
Correct |
26 ms |
60924 KB |
Output is correct |
16 |
Correct |
27 ms |
60996 KB |
Output is correct |
17 |
Correct |
27 ms |
61004 KB |
Output is correct |
18 |
Correct |
31 ms |
61020 KB |
Output is correct |
19 |
Correct |
30 ms |
61516 KB |
Output is correct |
20 |
Correct |
34 ms |
61828 KB |
Output is correct |
21 |
Correct |
37 ms |
61872 KB |
Output is correct |
22 |
Correct |
28 ms |
62004 KB |
Output is correct |
23 |
Correct |
29 ms |
62044 KB |
Output is correct |
24 |
Correct |
34 ms |
62052 KB |
Output is correct |
25 |
Correct |
43 ms |
62084 KB |
Output is correct |
26 |
Correct |
90 ms |
61928 KB |
Output is correct |
27 |
Correct |
197 ms |
62028 KB |
Output is correct |
28 |
Correct |
288 ms |
62076 KB |
Output is correct |