#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mxN = 3e3 + 5;
ll n,dp[mxN][mxN][3],ii,jj,m;
char a[mxN][mxN];
bool check(ll i, ll j, char ch){
if(i >= n or i < 0 or j >= m or j < 0) return false;
return (a[i][j] == ch);
}
void f(ll i, ll j){
while(i >= 0 and j < m){
ii = i;
jj = j;
if(j > 0 and i + 1 < n){
ll x = max(dp[i + 1][j - 1][1], dp[i + 1][j - 1][0]);
dp[i][j][2] = max(x, dp[i + 1][j - 1][2]);
}
if(a[i][j] != 'R'){
i--;
j++;
continue;
}
// 0 -- > R
// 1 -- > D
// 2 -- >
if(check(i + 1, j, 'G') and check(i + 2, j, 'W')){
if(j > 0 and i + 1 < n){
dp[i][j][1] = dp[i + 1][j - 1][1] + 1;
}
else dp[i][j][1] = 1;
if(j > 1 and i + 2 < n){
dp[i][j][1] = max(dp[i][j][1], max(dp[i + 2][j - 2][1], dp[i + 2][j - 2][2]) + 1);
}
}
if(check(i, j + 1, 'G') and check(i, j + 2, 'W')){
dp[i][j][0] = dp[i][j][2] + 1;
}
i--;
j++;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++) cin >> a[i][j];
}
ll ans = 0;
for(int i = 0; i < n; i++){
f(i, 0);
ans += max(dp[ii][jj][0], max(dp[ii][jj][1], dp[ii][jj][2]));
// cout << i << ' ' << ii << ' ' << jj << ' ' << max(dp[ii][jj][0], dp[ii][jj][1]) << '\n';
}
for(int j = 1; j < m; j++){
f(n - 1, j);
ans += max(dp[ii][jj][0], max(dp[ii][jj][1], dp[ii][jj][2]));
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2516 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2516 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
0 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
0 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
0 ms |
2512 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2392 KB |
Output is correct |
51 |
Correct |
1 ms |
2396 KB |
Output is correct |
52 |
Correct |
0 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2516 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
0 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
0 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
0 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
0 ms |
2512 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2392 KB |
Output is correct |
51 |
Correct |
1 ms |
2396 KB |
Output is correct |
52 |
Correct |
0 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
0 ms |
2516 KB |
Output is correct |
55 |
Correct |
2 ms |
17808 KB |
Output is correct |
56 |
Correct |
1 ms |
2396 KB |
Output is correct |
57 |
Correct |
8 ms |
36444 KB |
Output is correct |
58 |
Correct |
32 ms |
34560 KB |
Output is correct |
59 |
Correct |
249 ms |
229620 KB |
Output is correct |
60 |
Correct |
262 ms |
229552 KB |
Output is correct |
61 |
Correct |
256 ms |
229748 KB |
Output is correct |
62 |
Correct |
1 ms |
2396 KB |
Output is correct |
63 |
Correct |
241 ms |
229356 KB |
Output is correct |
64 |
Correct |
250 ms |
229620 KB |
Output is correct |
65 |
Correct |
268 ms |
229748 KB |
Output is correct |
66 |
Correct |
296 ms |
229768 KB |
Output is correct |
67 |
Correct |
316 ms |
229488 KB |
Output is correct |
68 |
Correct |
390 ms |
229704 KB |
Output is correct |
69 |
Correct |
258 ms |
229612 KB |
Output is correct |
70 |
Correct |
38 ms |
50752 KB |
Output is correct |
71 |
Correct |
38 ms |
50820 KB |
Output is correct |
72 |
Correct |
27 ms |
50780 KB |
Output is correct |
73 |
Correct |
24 ms |
50892 KB |
Output is correct |
74 |
Correct |
35 ms |
50836 KB |
Output is correct |
75 |
Correct |
30 ms |
50808 KB |
Output is correct |
76 |
Correct |
25 ms |
50812 KB |
Output is correct |
77 |
Correct |
24 ms |
50780 KB |
Output is correct |
78 |
Correct |
31 ms |
50924 KB |
Output is correct |
79 |
Correct |
29 ms |
50780 KB |
Output is correct |
80 |
Correct |
39 ms |
50816 KB |
Output is correct |
81 |
Correct |
39 ms |
50924 KB |
Output is correct |
82 |
Correct |
36 ms |
50908 KB |
Output is correct |
83 |
Correct |
39 ms |
50772 KB |
Output is correct |
84 |
Correct |
39 ms |
50772 KB |
Output is correct |
85 |
Correct |
29 ms |
50772 KB |
Output is correct |
86 |
Correct |
27 ms |
50816 KB |
Output is correct |
87 |
Correct |
27 ms |
50816 KB |
Output is correct |
88 |
Correct |
25 ms |
50880 KB |
Output is correct |
89 |
Correct |
35 ms |
50808 KB |
Output is correct |
90 |
Correct |
35 ms |
50716 KB |
Output is correct |