#include <bits/stdc++.h>
#define name "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define pb push_back
#define all(v) v.begin(), v.end()
#define maxn 255
const int M = 1e9 + 7;
using namespace std;
int m, n, full, pre[1 << 10], dp[1 << 10];
char s[1003][11];
void sol(){
full = (1 << m) - 1;
memset(pre, 0x3f, sizeof(pre));
pre[0] = 0;
fi(j, 0, n - 1){
fi(i, 0, m - 1){
fi(tt, 0, full){
// if i-th bit of tt = 0 -> cell(j, i) is shut by a horizontal tape
// if i-th bit of tt = 1 -> cell(j, i) is shut by a vertical tape
if(s[j][i] == '.'){
if(getbit(tt, i)) dp[tt] = 1e9;
else dp[tt] = min(pre[tt], pre[tt^(1 << i)]);
continue;
}
if(getbit(tt, i)) dp[tt] = min(pre[tt], pre[tt^(1 << i)] + 1);
else{
dp[tt] = min(pre[tt], pre[tt^(1 << i)]);
if(i == 0 || s[j][i - 1] == '.' || getbit(tt, i - 1)) dp[tt]++;
}
}
swap(pre, dp);
}
}
int res = 1e9;
fi(tt, 0, full) res = min(res, pre[tt]);
cout << res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//freopen(name".in","r",stdin);
//freopen(name".out","w",stdout);
cin >> n >> m;
fi(i, 0, n - 1)
fi(j, 0, m - 1) cin >> s[i][j];
sol();
return 0;
}
Compilation message
Main.cpp: In function 'void sol()':
Main.cpp:35:69: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
35 | if(i == 0 || s[j][i - 1] == '.' || getbit(tt, i - 1)) dp[tt]++;
| ~~^~~
Main.cpp:9:29: note: in definition of macro 'getbit'
9 | #define getbit(i, j) ((i >> j) & 1)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
18 ms |
348 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
12 ms |
348 KB |
Output is correct |
5 |
Correct |
27 ms |
352 KB |
Output is correct |
6 |
Correct |
28 ms |
332 KB |
Output is correct |
7 |
Correct |
28 ms |
332 KB |
Output is correct |
8 |
Correct |
20 ms |
340 KB |
Output is correct |
9 |
Correct |
29 ms |
340 KB |
Output is correct |
10 |
Correct |
25 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
18 ms |
348 KB |
Output is correct |
3 |
Correct |
8 ms |
348 KB |
Output is correct |
4 |
Correct |
12 ms |
348 KB |
Output is correct |
5 |
Correct |
27 ms |
352 KB |
Output is correct |
6 |
Correct |
28 ms |
332 KB |
Output is correct |
7 |
Correct |
28 ms |
332 KB |
Output is correct |
8 |
Correct |
20 ms |
340 KB |
Output is correct |
9 |
Correct |
29 ms |
340 KB |
Output is correct |
10 |
Correct |
25 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
4 ms |
340 KB |
Output is correct |
20 |
Correct |
8 ms |
340 KB |
Output is correct |
21 |
Correct |
13 ms |
328 KB |
Output is correct |
22 |
Correct |
21 ms |
352 KB |
Output is correct |
23 |
Correct |
19 ms |
356 KB |
Output is correct |
24 |
Correct |
19 ms |
340 KB |
Output is correct |
25 |
Correct |
21 ms |
348 KB |
Output is correct |
26 |
Correct |
22 ms |
348 KB |
Output is correct |
27 |
Correct |
23 ms |
352 KB |
Output is correct |
28 |
Correct |
23 ms |
328 KB |
Output is correct |