#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
char s[3003][3003];
int n , m;
int ans = 0;
bool can[2][3003][3003];
int dp[3003][3003][3];
int32_t main(){
scanf("%d%d" , &n , &m);
for(int i = 0 ; i < n; i ++)
for(int j = 0 ; j < m ; j ++) scanf(" %c" , &s[i][j]);
for(int i = 0 ; i < n; i++){
for(int j = 0 ; j < m ;j ++){
if(s[i][j] == 'G'){
if((j+1) < m && s[i][j+1] == 'W' && (j-1) >= 0 && s[i][j-1] == 'R') can[0][i][j] = true;
if((i+1) < n && s[i+1][j] == 'W' && (i-1) >= 0 && s[i-1][j] == 'R') can[1][i][j] = true;
}
}
}
for(int i = n-1 ; i >= 0 ; i--){
for(int j = 0 ; j < m; j ++){
dp[i][j][1] = can[0][i][j];
dp[i][j][2] = can[1][i][j];
if((i+1) < n && (j-1) >= 0){
dp[i][j][0] = max(dp[i+1][j-1][0] , max(dp[i+1][j-1][1] , dp[i+1][j-1][2]));
dp[i][j][1] = max(dp[i+1][j-1][1] , dp[i+1][j-1][0]) + (can[0][i][j]);
dp[i][j][2] = max(dp[i+1][j-1][2] , dp[i+1][j-1][0]) + (can[1][i][j]);
}
}
}
int ans = 0;
for(int i = 0 ; i < m; i ++){
pair<int,int> curr = pair<int,int>(0 , i);
ans += max(dp[curr.F][curr.S][0] , max(dp[curr.F][curr.S][1] , dp[curr.F][curr.S][2]));
}
for(int j = 0 ; j < n ; j ++){
pair<int,int> curr = pair<int,int>(j , m-1);
ans += max(dp[curr.F][curr.S][0] , max(dp[curr.F][curr.S][1] , dp[curr.F][curr.S][2]));
}
pair<int,int> curr = pair<int,int>(0 , m-1);
ans -= max(dp[curr.F][curr.S][0] , max(dp[curr.F][curr.S][1] , dp[curr.F][curr.S][2]));
printf("%d\n" , ans);
}
Compilation message
dango_maker.cpp: In function 'int32_t main()':
dango_maker.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d" , &n , &m);
~~~~~^~~~~~~~~~~~~~~~~~
dango_maker.cpp:13:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int j = 0 ; j < m ; j ++) scanf(" %c" , &s[i][j]);
~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
400 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
12 |
Correct |
2 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
2 ms |
740 KB |
Output is correct |
15 |
Correct |
2 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
400 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
12 |
Correct |
2 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
2 ms |
740 KB |
Output is correct |
15 |
Correct |
2 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
3 ms |
740 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
8 ms |
740 KB |
Output is correct |
21 |
Correct |
2 ms |
740 KB |
Output is correct |
22 |
Correct |
2 ms |
740 KB |
Output is correct |
23 |
Correct |
2 ms |
740 KB |
Output is correct |
24 |
Correct |
2 ms |
740 KB |
Output is correct |
25 |
Correct |
2 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
5 ms |
868 KB |
Output is correct |
28 |
Correct |
3 ms |
868 KB |
Output is correct |
29 |
Correct |
2 ms |
872 KB |
Output is correct |
30 |
Correct |
2 ms |
872 KB |
Output is correct |
31 |
Correct |
2 ms |
872 KB |
Output is correct |
32 |
Correct |
12 ms |
872 KB |
Output is correct |
33 |
Correct |
2 ms |
888 KB |
Output is correct |
34 |
Correct |
2 ms |
892 KB |
Output is correct |
35 |
Correct |
3 ms |
1148 KB |
Output is correct |
36 |
Correct |
2 ms |
1148 KB |
Output is correct |
37 |
Correct |
2 ms |
1148 KB |
Output is correct |
38 |
Correct |
2 ms |
1148 KB |
Output is correct |
39 |
Correct |
2 ms |
1148 KB |
Output is correct |
40 |
Correct |
3 ms |
1148 KB |
Output is correct |
41 |
Correct |
2 ms |
1148 KB |
Output is correct |
42 |
Correct |
2 ms |
1228 KB |
Output is correct |
43 |
Correct |
2 ms |
1232 KB |
Output is correct |
44 |
Correct |
2 ms |
1232 KB |
Output is correct |
45 |
Correct |
2 ms |
1232 KB |
Output is correct |
46 |
Correct |
2 ms |
1268 KB |
Output is correct |
47 |
Correct |
2 ms |
1268 KB |
Output is correct |
48 |
Correct |
2 ms |
1268 KB |
Output is correct |
49 |
Correct |
2 ms |
1268 KB |
Output is correct |
50 |
Correct |
2 ms |
1268 KB |
Output is correct |
51 |
Correct |
2 ms |
1268 KB |
Output is correct |
52 |
Correct |
3 ms |
1268 KB |
Output is correct |
53 |
Correct |
2 ms |
1268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
400 KB |
Output is correct |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
632 KB |
Output is correct |
6 |
Correct |
2 ms |
632 KB |
Output is correct |
7 |
Correct |
2 ms |
632 KB |
Output is correct |
8 |
Correct |
2 ms |
740 KB |
Output is correct |
9 |
Correct |
2 ms |
740 KB |
Output is correct |
10 |
Correct |
2 ms |
740 KB |
Output is correct |
11 |
Correct |
2 ms |
740 KB |
Output is correct |
12 |
Correct |
2 ms |
740 KB |
Output is correct |
13 |
Correct |
2 ms |
740 KB |
Output is correct |
14 |
Correct |
2 ms |
740 KB |
Output is correct |
15 |
Correct |
2 ms |
740 KB |
Output is correct |
16 |
Correct |
2 ms |
740 KB |
Output is correct |
17 |
Correct |
2 ms |
740 KB |
Output is correct |
18 |
Correct |
3 ms |
740 KB |
Output is correct |
19 |
Correct |
2 ms |
740 KB |
Output is correct |
20 |
Correct |
8 ms |
740 KB |
Output is correct |
21 |
Correct |
2 ms |
740 KB |
Output is correct |
22 |
Correct |
2 ms |
740 KB |
Output is correct |
23 |
Correct |
2 ms |
740 KB |
Output is correct |
24 |
Correct |
2 ms |
740 KB |
Output is correct |
25 |
Correct |
2 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
5 ms |
868 KB |
Output is correct |
28 |
Correct |
3 ms |
868 KB |
Output is correct |
29 |
Correct |
2 ms |
872 KB |
Output is correct |
30 |
Correct |
2 ms |
872 KB |
Output is correct |
31 |
Correct |
2 ms |
872 KB |
Output is correct |
32 |
Correct |
12 ms |
872 KB |
Output is correct |
33 |
Correct |
2 ms |
888 KB |
Output is correct |
34 |
Correct |
2 ms |
892 KB |
Output is correct |
35 |
Correct |
3 ms |
1148 KB |
Output is correct |
36 |
Correct |
2 ms |
1148 KB |
Output is correct |
37 |
Correct |
2 ms |
1148 KB |
Output is correct |
38 |
Correct |
2 ms |
1148 KB |
Output is correct |
39 |
Correct |
2 ms |
1148 KB |
Output is correct |
40 |
Correct |
3 ms |
1148 KB |
Output is correct |
41 |
Correct |
2 ms |
1148 KB |
Output is correct |
42 |
Correct |
2 ms |
1228 KB |
Output is correct |
43 |
Correct |
2 ms |
1232 KB |
Output is correct |
44 |
Correct |
2 ms |
1232 KB |
Output is correct |
45 |
Correct |
2 ms |
1232 KB |
Output is correct |
46 |
Correct |
2 ms |
1268 KB |
Output is correct |
47 |
Correct |
2 ms |
1268 KB |
Output is correct |
48 |
Correct |
2 ms |
1268 KB |
Output is correct |
49 |
Correct |
2 ms |
1268 KB |
Output is correct |
50 |
Correct |
2 ms |
1268 KB |
Output is correct |
51 |
Correct |
2 ms |
1268 KB |
Output is correct |
52 |
Correct |
3 ms |
1268 KB |
Output is correct |
53 |
Correct |
2 ms |
1268 KB |
Output is correct |
54 |
Correct |
2 ms |
1268 KB |
Output is correct |
55 |
Correct |
22 ms |
22440 KB |
Output is correct |
56 |
Correct |
3 ms |
22440 KB |
Output is correct |
57 |
Correct |
20 ms |
23504 KB |
Output is correct |
58 |
Correct |
101 ms |
26668 KB |
Output is correct |
59 |
Correct |
763 ms |
143064 KB |
Output is correct |
60 |
Correct |
752 ms |
152020 KB |
Output is correct |
61 |
Correct |
771 ms |
160892 KB |
Output is correct |
62 |
Correct |
3 ms |
160892 KB |
Output is correct |
63 |
Correct |
766 ms |
169292 KB |
Output is correct |
64 |
Correct |
743 ms |
178152 KB |
Output is correct |
65 |
Correct |
697 ms |
187048 KB |
Output is correct |
66 |
Correct |
651 ms |
195792 KB |
Output is correct |
67 |
Correct |
655 ms |
195792 KB |
Output is correct |
68 |
Correct |
693 ms |
202812 KB |
Output is correct |
69 |
Correct |
662 ms |
218112 KB |
Output is correct |
70 |
Correct |
84 ms |
218112 KB |
Output is correct |
71 |
Correct |
82 ms |
218112 KB |
Output is correct |
72 |
Correct |
81 ms |
218112 KB |
Output is correct |
73 |
Correct |
121 ms |
218112 KB |
Output is correct |
74 |
Correct |
102 ms |
218112 KB |
Output is correct |
75 |
Correct |
81 ms |
218112 KB |
Output is correct |
76 |
Correct |
112 ms |
218112 KB |
Output is correct |
77 |
Correct |
85 ms |
218112 KB |
Output is correct |
78 |
Correct |
88 ms |
218112 KB |
Output is correct |
79 |
Correct |
86 ms |
218112 KB |
Output is correct |
80 |
Correct |
85 ms |
218112 KB |
Output is correct |
81 |
Correct |
83 ms |
218112 KB |
Output is correct |
82 |
Correct |
82 ms |
218112 KB |
Output is correct |
83 |
Correct |
89 ms |
218112 KB |
Output is correct |
84 |
Correct |
90 ms |
218112 KB |
Output is correct |
85 |
Correct |
84 ms |
218112 KB |
Output is correct |
86 |
Correct |
85 ms |
218112 KB |
Output is correct |
87 |
Correct |
82 ms |
218112 KB |
Output is correct |
88 |
Correct |
84 ms |
218112 KB |
Output is correct |
89 |
Correct |
81 ms |
218112 KB |
Output is correct |
90 |
Correct |
85 ms |
218112 KB |
Output is correct |