#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=3e3+10;
int n, m, dp[MAX][3][3];
pair<bool, bool>t[MAX][MAX];
char c[MAX][MAX];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
cin>>c[i][j];
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
t[i][j].fi=(i+2<=n && c[i][j]=='R' && c[i+1][j]=='G' && c[i+2][j]=='W');
t[i][j].se=(j+2<=m && c[i][j]=='R' && c[i][j+1]=='G' && c[i][j+2]=='W');
}
}
int wyn=0;
for(int i=1; i<=n+m-1; i++){
int sx, sy;
if(i<=n) sx=i, sy=1;
else sx=n, sy=i-n+1;
for(int x=sx, y=sy, l=1; x>=1&&y<=m; x--, y++, l++){
for(int i1=0; i1<=2; i1++)
for(int i2=0; i2<=2; i2++)
dp[l][0][i1]=max(dp[l][0][i1], dp[l-1][i1][i2]);
if(t[x][y].fi){
for(int i1=0; i1<2; i1++)
for(int i2=0; i2<2; i2++)
dp[l][1][i1]=max(dp[l][1][i1], dp[l-1][i1][i2]+1);
}
if(t[x][y].se){
for(int i1=0; i1<=2; i1++)
for(int i2=0; i2<=2; i2++)
dp[l][2][i1]=max(dp[l][2][i1], dp[l-1][i1][i2]+1);
}
if(x==1||y==m){
int maxi=0;
for(int i1=0; i1<=2; i1++)
for(int i2=0; i2<=2; i2++)
maxi=max(maxi, dp[l][i1][i2]);
wyn+=maxi;
}
}
for(int x=sx, y=sy, l=1; x>=1&&y<=m; x--, y++, l++)
for(int i1=0; i1<=2; i1++)
for(int i2=0; i2<=2; i2++)
dp[l][i1][i2]=0;
}
cout<<wyn<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
10 ms |
21076 KB |
Output is correct |
56 |
Correct |
1 ms |
336 KB |
Output is correct |
57 |
Correct |
7 ms |
14292 KB |
Output is correct |
58 |
Correct |
48 ms |
9292 KB |
Output is correct |
59 |
Correct |
363 ms |
27008 KB |
Output is correct |
60 |
Correct |
404 ms |
27228 KB |
Output is correct |
61 |
Correct |
365 ms |
27100 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
402 ms |
27120 KB |
Output is correct |
64 |
Correct |
367 ms |
27020 KB |
Output is correct |
65 |
Correct |
375 ms |
27124 KB |
Output is correct |
66 |
Correct |
420 ms |
27092 KB |
Output is correct |
67 |
Correct |
302 ms |
27232 KB |
Output is correct |
68 |
Correct |
363 ms |
27120 KB |
Output is correct |
69 |
Correct |
311 ms |
27120 KB |
Output is correct |
70 |
Correct |
63 ms |
9388 KB |
Output is correct |
71 |
Correct |
51 ms |
9344 KB |
Output is correct |
72 |
Correct |
36 ms |
9328 KB |
Output is correct |
73 |
Correct |
55 ms |
9376 KB |
Output is correct |
74 |
Correct |
34 ms |
9296 KB |
Output is correct |
75 |
Correct |
38 ms |
9388 KB |
Output is correct |
76 |
Correct |
49 ms |
9376 KB |
Output is correct |
77 |
Correct |
40 ms |
9296 KB |
Output is correct |
78 |
Correct |
35 ms |
9372 KB |
Output is correct |
79 |
Correct |
37 ms |
9372 KB |
Output is correct |
80 |
Correct |
36 ms |
9320 KB |
Output is correct |
81 |
Correct |
34 ms |
9388 KB |
Output is correct |
82 |
Correct |
36 ms |
9392 KB |
Output is correct |
83 |
Correct |
36 ms |
9320 KB |
Output is correct |
84 |
Correct |
37 ms |
9288 KB |
Output is correct |
85 |
Correct |
37 ms |
9276 KB |
Output is correct |
86 |
Correct |
51 ms |
9388 KB |
Output is correct |
87 |
Correct |
43 ms |
9284 KB |
Output is correct |
88 |
Correct |
40 ms |
9384 KB |
Output is correct |
89 |
Correct |
38 ms |
9296 KB |
Output is correct |
90 |
Correct |
38 ms |
9296 KB |
Output is correct |