#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 2000005
#define S second
#define F first
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector<pll>
ll n,m,dp[2][MAX];
string a[MAX];
ll comp(ll z,ll i,ll j){
pll x={min(i,n-1)-j,max(0LL,i-n+1)+j};
if(z==0){
if(x.S-1>=0 && x.S+1<m){
if(a[x.F][x.S-1]=='R' && a[x.F][x.S]=='G' && a[x.F][x.S+1]=='W')return 1;
return 0;
}
return 0;
}
if(x.F-1>=0 && x.F+1<n){
if(a[x.F-1][x.S]=='R' && a[x.F][x.S]=='G' && a[x.F+1][x.S]=='W')return 1;
return 0;
}
return 0;
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i];
}
ll r=0,h=0;
for(int i=0;i<n+m-1;i++){
if(i<n)h++;
if(i>=m)h--;
if(i<1)continue;
for(int j=0;j<h;j++){
dp[0][j]=dp[1][j]=0;
if(j>=1){
dp[0][j]=dp[0][j-1];
dp[1][j]=dp[1][j-1];
}
if(j>=2){
dp[0][j]=max(dp[0][j],dp[1][j-2]);
dp[1][j]=max(dp[1][j],dp[0][j-2]);
}
if(comp(0,i,j)==1)dp[0][j]++;
if(comp(1,i,j)==1)dp[1][j]++;
// cout<<"="<<dp[0][j]<<" "<<dp[1][j]<<"\n";
}
//cout<<"...\n";
r+=max(dp[0][h-1],dp[1][h-1]);
}
cout<<r<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
64080 KB |
Output is correct |
2 |
Correct |
10 ms |
66128 KB |
Output is correct |
3 |
Correct |
11 ms |
66140 KB |
Output is correct |
4 |
Correct |
12 ms |
66256 KB |
Output is correct |
5 |
Correct |
12 ms |
66128 KB |
Output is correct |
6 |
Correct |
11 ms |
66128 KB |
Output is correct |
7 |
Correct |
11 ms |
66292 KB |
Output is correct |
8 |
Correct |
11 ms |
66128 KB |
Output is correct |
9 |
Correct |
12 ms |
66128 KB |
Output is correct |
10 |
Correct |
12 ms |
66128 KB |
Output is correct |
11 |
Correct |
12 ms |
66240 KB |
Output is correct |
12 |
Correct |
11 ms |
66128 KB |
Output is correct |
13 |
Correct |
12 ms |
66128 KB |
Output is correct |
14 |
Correct |
11 ms |
66296 KB |
Output is correct |
15 |
Correct |
11 ms |
66128 KB |
Output is correct |
16 |
Correct |
11 ms |
66128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
64080 KB |
Output is correct |
2 |
Correct |
10 ms |
66128 KB |
Output is correct |
3 |
Correct |
11 ms |
66140 KB |
Output is correct |
4 |
Correct |
12 ms |
66256 KB |
Output is correct |
5 |
Correct |
12 ms |
66128 KB |
Output is correct |
6 |
Correct |
11 ms |
66128 KB |
Output is correct |
7 |
Correct |
11 ms |
66292 KB |
Output is correct |
8 |
Correct |
11 ms |
66128 KB |
Output is correct |
9 |
Correct |
12 ms |
66128 KB |
Output is correct |
10 |
Correct |
12 ms |
66128 KB |
Output is correct |
11 |
Correct |
12 ms |
66240 KB |
Output is correct |
12 |
Correct |
11 ms |
66128 KB |
Output is correct |
13 |
Correct |
12 ms |
66128 KB |
Output is correct |
14 |
Correct |
11 ms |
66296 KB |
Output is correct |
15 |
Correct |
11 ms |
66128 KB |
Output is correct |
16 |
Correct |
11 ms |
66128 KB |
Output is correct |
17 |
Correct |
13 ms |
66128 KB |
Output is correct |
18 |
Correct |
11 ms |
66128 KB |
Output is correct |
19 |
Correct |
12 ms |
66128 KB |
Output is correct |
20 |
Correct |
12 ms |
66188 KB |
Output is correct |
21 |
Correct |
12 ms |
66140 KB |
Output is correct |
22 |
Correct |
11 ms |
66128 KB |
Output is correct |
23 |
Correct |
12 ms |
66128 KB |
Output is correct |
24 |
Correct |
11 ms |
66128 KB |
Output is correct |
25 |
Correct |
11 ms |
66184 KB |
Output is correct |
26 |
Correct |
12 ms |
66128 KB |
Output is correct |
27 |
Correct |
13 ms |
66128 KB |
Output is correct |
28 |
Correct |
13 ms |
66128 KB |
Output is correct |
29 |
Correct |
14 ms |
66128 KB |
Output is correct |
30 |
Correct |
11 ms |
66128 KB |
Output is correct |
31 |
Correct |
11 ms |
66128 KB |
Output is correct |
32 |
Correct |
13 ms |
66128 KB |
Output is correct |
33 |
Correct |
11 ms |
66128 KB |
Output is correct |
34 |
Correct |
12 ms |
66128 KB |
Output is correct |
35 |
Correct |
11 ms |
66128 KB |
Output is correct |
36 |
Correct |
12 ms |
66128 KB |
Output is correct |
37 |
Correct |
13 ms |
66216 KB |
Output is correct |
38 |
Correct |
13 ms |
66284 KB |
Output is correct |
39 |
Correct |
13 ms |
66296 KB |
Output is correct |
40 |
Correct |
13 ms |
66128 KB |
Output is correct |
41 |
Correct |
11 ms |
66156 KB |
Output is correct |
42 |
Correct |
13 ms |
66128 KB |
Output is correct |
43 |
Correct |
11 ms |
66264 KB |
Output is correct |
44 |
Correct |
11 ms |
66128 KB |
Output is correct |
45 |
Correct |
11 ms |
66128 KB |
Output is correct |
46 |
Correct |
11 ms |
66312 KB |
Output is correct |
47 |
Correct |
11 ms |
66296 KB |
Output is correct |
48 |
Correct |
11 ms |
66128 KB |
Output is correct |
49 |
Correct |
14 ms |
66384 KB |
Output is correct |
50 |
Correct |
12 ms |
66128 KB |
Output is correct |
51 |
Correct |
11 ms |
66128 KB |
Output is correct |
52 |
Correct |
11 ms |
66308 KB |
Output is correct |
53 |
Correct |
11 ms |
66128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
64080 KB |
Output is correct |
2 |
Correct |
10 ms |
66128 KB |
Output is correct |
3 |
Correct |
11 ms |
66140 KB |
Output is correct |
4 |
Correct |
12 ms |
66256 KB |
Output is correct |
5 |
Correct |
12 ms |
66128 KB |
Output is correct |
6 |
Correct |
11 ms |
66128 KB |
Output is correct |
7 |
Correct |
11 ms |
66292 KB |
Output is correct |
8 |
Correct |
11 ms |
66128 KB |
Output is correct |
9 |
Correct |
12 ms |
66128 KB |
Output is correct |
10 |
Correct |
12 ms |
66128 KB |
Output is correct |
11 |
Correct |
12 ms |
66240 KB |
Output is correct |
12 |
Correct |
11 ms |
66128 KB |
Output is correct |
13 |
Correct |
12 ms |
66128 KB |
Output is correct |
14 |
Correct |
11 ms |
66296 KB |
Output is correct |
15 |
Correct |
11 ms |
66128 KB |
Output is correct |
16 |
Correct |
11 ms |
66128 KB |
Output is correct |
17 |
Correct |
13 ms |
66128 KB |
Output is correct |
18 |
Correct |
11 ms |
66128 KB |
Output is correct |
19 |
Correct |
12 ms |
66128 KB |
Output is correct |
20 |
Correct |
12 ms |
66188 KB |
Output is correct |
21 |
Correct |
12 ms |
66140 KB |
Output is correct |
22 |
Correct |
11 ms |
66128 KB |
Output is correct |
23 |
Correct |
12 ms |
66128 KB |
Output is correct |
24 |
Correct |
11 ms |
66128 KB |
Output is correct |
25 |
Correct |
11 ms |
66184 KB |
Output is correct |
26 |
Correct |
12 ms |
66128 KB |
Output is correct |
27 |
Correct |
13 ms |
66128 KB |
Output is correct |
28 |
Correct |
13 ms |
66128 KB |
Output is correct |
29 |
Correct |
14 ms |
66128 KB |
Output is correct |
30 |
Correct |
11 ms |
66128 KB |
Output is correct |
31 |
Correct |
11 ms |
66128 KB |
Output is correct |
32 |
Correct |
13 ms |
66128 KB |
Output is correct |
33 |
Correct |
11 ms |
66128 KB |
Output is correct |
34 |
Correct |
12 ms |
66128 KB |
Output is correct |
35 |
Correct |
11 ms |
66128 KB |
Output is correct |
36 |
Correct |
12 ms |
66128 KB |
Output is correct |
37 |
Correct |
13 ms |
66216 KB |
Output is correct |
38 |
Correct |
13 ms |
66284 KB |
Output is correct |
39 |
Correct |
13 ms |
66296 KB |
Output is correct |
40 |
Correct |
13 ms |
66128 KB |
Output is correct |
41 |
Correct |
11 ms |
66156 KB |
Output is correct |
42 |
Correct |
13 ms |
66128 KB |
Output is correct |
43 |
Correct |
11 ms |
66264 KB |
Output is correct |
44 |
Correct |
11 ms |
66128 KB |
Output is correct |
45 |
Correct |
11 ms |
66128 KB |
Output is correct |
46 |
Correct |
11 ms |
66312 KB |
Output is correct |
47 |
Correct |
11 ms |
66296 KB |
Output is correct |
48 |
Correct |
11 ms |
66128 KB |
Output is correct |
49 |
Correct |
14 ms |
66384 KB |
Output is correct |
50 |
Correct |
12 ms |
66128 KB |
Output is correct |
51 |
Correct |
11 ms |
66128 KB |
Output is correct |
52 |
Correct |
11 ms |
66308 KB |
Output is correct |
53 |
Correct |
11 ms |
66128 KB |
Output is correct |
54 |
Correct |
12 ms |
66128 KB |
Output is correct |
55 |
Correct |
11 ms |
66240 KB |
Output is correct |
56 |
Correct |
11 ms |
66140 KB |
Output is correct |
57 |
Correct |
12 ms |
65152 KB |
Output is correct |
58 |
Correct |
49 ms |
66888 KB |
Output is correct |
59 |
Correct |
267 ms |
86352 KB |
Output is correct |
60 |
Correct |
314 ms |
84040 KB |
Output is correct |
61 |
Correct |
296 ms |
86344 KB |
Output is correct |
62 |
Correct |
12 ms |
66128 KB |
Output is correct |
63 |
Correct |
307 ms |
85884 KB |
Output is correct |
64 |
Correct |
217 ms |
83276 KB |
Output is correct |
65 |
Correct |
225 ms |
86224 KB |
Output is correct |
66 |
Correct |
208 ms |
86352 KB |
Output is correct |
67 |
Correct |
237 ms |
86344 KB |
Output is correct |
68 |
Correct |
210 ms |
86348 KB |
Output is correct |
69 |
Correct |
213 ms |
86344 KB |
Output is correct |
70 |
Correct |
46 ms |
68952 KB |
Output is correct |
71 |
Correct |
45 ms |
68936 KB |
Output is correct |
72 |
Correct |
44 ms |
69144 KB |
Output is correct |
73 |
Correct |
42 ms |
68964 KB |
Output is correct |
74 |
Correct |
42 ms |
68944 KB |
Output is correct |
75 |
Correct |
43 ms |
68936 KB |
Output is correct |
76 |
Correct |
34 ms |
69068 KB |
Output is correct |
77 |
Correct |
34 ms |
68944 KB |
Output is correct |
78 |
Correct |
35 ms |
68944 KB |
Output is correct |
79 |
Correct |
35 ms |
69104 KB |
Output is correct |
80 |
Correct |
35 ms |
68944 KB |
Output is correct |
81 |
Correct |
40 ms |
68904 KB |
Output is correct |
82 |
Correct |
34 ms |
68944 KB |
Output is correct |
83 |
Correct |
35 ms |
68944 KB |
Output is correct |
84 |
Correct |
35 ms |
69152 KB |
Output is correct |
85 |
Correct |
36 ms |
68944 KB |
Output is correct |
86 |
Correct |
35 ms |
68964 KB |
Output is correct |
87 |
Correct |
39 ms |
68944 KB |
Output is correct |
88 |
Correct |
32 ms |
68944 KB |
Output is correct |
89 |
Correct |
36 ms |
69148 KB |
Output is correct |
90 |
Correct |
34 ms |
68944 KB |
Output is correct |