#include <bits/stdc++.h>
using namespace std;
bool used[1005][15];
int N,M;
int memo[1005][10][1030][2];
int func(int n, int pos, int bitm, bool c){
if (pos==-1){
pos = M-1;
n--;
if (c) return 999999999;
}
if (n<0){
return bitm==0?0:999999999;
}
if (memo[n][pos][bitm][c]!=-1) return memo[n][pos][bitm][c];
if ((bitm&(1<<pos))!=0 && used[n][pos]){
return 999999999;
}
if (used[n][pos] && c){
return 999999999;
}
if (used[n][pos]){
return memo[n][pos][bitm][c] = func(n,pos-1,bitm,c);
}
if (c && (bitm&(1<<pos))!=0) return 999999999;
int starthorz = 1+func(n,pos-1,bitm,false);
int startvert = 1+func(n,pos-1,bitm&~(1<<pos),false);
int usehorz = func(n,pos-1,bitm,true);
int usevert = func(n,pos-1,bitm|(1<<pos),false);
//printf("%d %d, %d %d %d %d\n",n,pos,starthorz,startvert,usehorz,usevert);
if (c){
return memo[n][pos][bitm][c] = min(starthorz,usehorz);
}
if (bitm&(1<<pos)){
return memo[n][pos][bitm][c] = min(startvert, usevert);
}
return memo[n][pos][bitm][c] = min(min(starthorz, usehorz),min(startvert,usevert));
}
int main(){
memset(memo,-1,sizeof(memo));
scanf("%d%d",&N,&M);
for (int x = 0; x<N; x++){
for (int y = 0; y<M; y++){
char c;
scanf(" %c",&c);
used[x][y] = c=='.';
}
}
printf("%d",func(N,-1,0,false));
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
45 | scanf("%d%d",&N,&M);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:49:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
49 | scanf(" %c",&c);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
81388 KB |
Output is correct |
2 |
Correct |
50 ms |
82688 KB |
Output is correct |
3 |
Correct |
49 ms |
82284 KB |
Output is correct |
4 |
Correct |
49 ms |
82540 KB |
Output is correct |
5 |
Correct |
54 ms |
82540 KB |
Output is correct |
6 |
Correct |
53 ms |
82540 KB |
Output is correct |
7 |
Correct |
53 ms |
82540 KB |
Output is correct |
8 |
Correct |
46 ms |
82540 KB |
Output is correct |
9 |
Correct |
49 ms |
82540 KB |
Output is correct |
10 |
Correct |
77 ms |
82796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
81388 KB |
Output is correct |
2 |
Correct |
44 ms |
81388 KB |
Output is correct |
3 |
Correct |
53 ms |
81388 KB |
Output is correct |
4 |
Correct |
46 ms |
81388 KB |
Output is correct |
5 |
Correct |
44 ms |
81388 KB |
Output is correct |
6 |
Correct |
43 ms |
81388 KB |
Output is correct |
7 |
Correct |
45 ms |
81388 KB |
Output is correct |
8 |
Correct |
44 ms |
81388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
81388 KB |
Output is correct |
2 |
Correct |
50 ms |
82688 KB |
Output is correct |
3 |
Correct |
49 ms |
82284 KB |
Output is correct |
4 |
Correct |
49 ms |
82540 KB |
Output is correct |
5 |
Correct |
54 ms |
82540 KB |
Output is correct |
6 |
Correct |
53 ms |
82540 KB |
Output is correct |
7 |
Correct |
53 ms |
82540 KB |
Output is correct |
8 |
Correct |
46 ms |
82540 KB |
Output is correct |
9 |
Correct |
49 ms |
82540 KB |
Output is correct |
10 |
Correct |
77 ms |
82796 KB |
Output is correct |
11 |
Correct |
44 ms |
81388 KB |
Output is correct |
12 |
Correct |
44 ms |
81388 KB |
Output is correct |
13 |
Correct |
53 ms |
81388 KB |
Output is correct |
14 |
Correct |
46 ms |
81388 KB |
Output is correct |
15 |
Correct |
44 ms |
81388 KB |
Output is correct |
16 |
Correct |
43 ms |
81388 KB |
Output is correct |
17 |
Correct |
45 ms |
81388 KB |
Output is correct |
18 |
Correct |
44 ms |
81388 KB |
Output is correct |
19 |
Correct |
45 ms |
82028 KB |
Output is correct |
20 |
Correct |
51 ms |
82412 KB |
Output is correct |
21 |
Correct |
57 ms |
82540 KB |
Output is correct |
22 |
Correct |
53 ms |
82540 KB |
Output is correct |
23 |
Correct |
47 ms |
82540 KB |
Output is correct |
24 |
Correct |
49 ms |
82540 KB |
Output is correct |
25 |
Correct |
62 ms |
82540 KB |
Output is correct |
26 |
Correct |
131 ms |
82540 KB |
Output is correct |
27 |
Correct |
267 ms |
82668 KB |
Output is correct |
28 |
Correct |
424 ms |
82668 KB |
Output is correct |