/*
www.youtube.com/YugiHackerChannel
oj.vnoi.info/user/YugiHackerKhongCopCode
*/
#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn
#define bit(n,i) ((n>>i)&1)
using namespace std;
int n, m;
char a[1003][11];
vector <int> f, pre;
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
f0 (i, n) f0 (j, m) cin >> a[i][j];
f.resize(1 << m), pre.resize(1 << m, 1e5);
pre[0] = 0;
f0 (i, n) f0 (j, m)
{
f0 (mask, 1 << m)
{
if (bit(mask, j))
{
if (a[i][j] == '.') f[mask] = 1e5; // ?
else f[mask] = min(pre[mask], pre[mask ^ (1 << j)] + 1);
// #
// v
// #
}
else
{
if (a[i][j] == '.')
f[mask] = min(pre[mask], pre[mask ^ (1 << j)]);
else if (j && a[i][j] == '#' && a[i][j-1] == '#' && bit(mask, j-1) == 0)
f[mask] = min(pre[mask], pre[mask ^ (1 << j)]); // # -> #
else
f[mask] = min(pre[mask], pre[mask ^ (1 << j)]) + 1;
}
}
pre = f;
}
cout << *min_element(pre.begin(), pre.end());
}
/*
5 8
#.##..#.
....###.
#.#.##..
#.#..#.#
##..####
*/
Compilation message
Main.cpp:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
15 | main()
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:40:80: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
40 | else if (j && a[i][j] == '#' && a[i][j-1] == '#' && bit(mask, j-1) == 0)
| ~^~
Main.cpp:10:23: note: in definition of macro 'bit'
10 | #define bit(n,i) ((n>>i)&1)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
18 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
340 KB |
Output is correct |
5 |
Correct |
18 ms |
340 KB |
Output is correct |
6 |
Correct |
18 ms |
336 KB |
Output is correct |
7 |
Correct |
18 ms |
352 KB |
Output is correct |
8 |
Correct |
17 ms |
340 KB |
Output is correct |
9 |
Correct |
17 ms |
340 KB |
Output is correct |
10 |
Correct |
20 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
18 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
340 KB |
Output is correct |
5 |
Correct |
18 ms |
340 KB |
Output is correct |
6 |
Correct |
18 ms |
336 KB |
Output is correct |
7 |
Correct |
18 ms |
352 KB |
Output is correct |
8 |
Correct |
17 ms |
340 KB |
Output is correct |
9 |
Correct |
17 ms |
340 KB |
Output is correct |
10 |
Correct |
20 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
324 KB |
Output is correct |
20 |
Correct |
5 ms |
336 KB |
Output is correct |
21 |
Correct |
9 ms |
336 KB |
Output is correct |
22 |
Correct |
17 ms |
348 KB |
Output is correct |
23 |
Correct |
18 ms |
340 KB |
Output is correct |
24 |
Correct |
17 ms |
340 KB |
Output is correct |
25 |
Correct |
18 ms |
340 KB |
Output is correct |
26 |
Correct |
19 ms |
352 KB |
Output is correct |
27 |
Correct |
21 ms |
340 KB |
Output is correct |
28 |
Correct |
21 ms |
340 KB |
Output is correct |