#include <bits/stdc++.h>
using namespace std;
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector g(n + 1, vector<char>(m + 1));
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> g[i][j];
}
}
int ans = 0;
for(int s = 2; s <= n + m; s++) {
vector dp(n + 1, vector<int>(3));
int p = 0;
for(int i = 1, j = s - i; i <= n; i++, j--) {
if(!(1 <= j && j <= m)) {
continue;
}
dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
if(g[i][j] == 'G') {
if(1 < i && i < n && g[i - 1][j] == 'R' && g[i + 1][j] == 'W') {
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
}
if(1 < j && j < m && g[i][j - 1] == 'R' && g[i][j + 1] == 'W') {
dp[i][2] = max(dp[i - 1][0], dp[i - 1][2]) + 1;
}
}
p = i;
}
ans += max({dp[p][0], dp[p][1], dp[p][2]});
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
324 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
320 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
324 KB |
Output is correct |
42 |
Correct |
1 ms |
324 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
324 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
320 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
324 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
320 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
324 KB |
Output is correct |
42 |
Correct |
1 ms |
324 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
324 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
320 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
316 KB |
Output is correct |
55 |
Correct |
353 ms |
644 KB |
Output is correct |
56 |
Correct |
1 ms |
336 KB |
Output is correct |
57 |
Correct |
148 ms |
544 KB |
Output is correct |
58 |
Correct |
95 ms |
2328 KB |
Output is correct |
59 |
Correct |
959 ms |
18340 KB |
Output is correct |
60 |
Correct |
1004 ms |
18456 KB |
Output is correct |
61 |
Correct |
996 ms |
18424 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
960 ms |
17600 KB |
Output is correct |
64 |
Correct |
936 ms |
18444 KB |
Output is correct |
65 |
Correct |
949 ms |
18336 KB |
Output is correct |
66 |
Correct |
919 ms |
18304 KB |
Output is correct |
67 |
Correct |
890 ms |
18328 KB |
Output is correct |
68 |
Correct |
953 ms |
18324 KB |
Output is correct |
69 |
Correct |
908 ms |
18256 KB |
Output is correct |
70 |
Correct |
91 ms |
2260 KB |
Output is correct |
71 |
Correct |
88 ms |
2380 KB |
Output is correct |
72 |
Correct |
92 ms |
2368 KB |
Output is correct |
73 |
Correct |
89 ms |
2364 KB |
Output is correct |
74 |
Correct |
95 ms |
2360 KB |
Output is correct |
75 |
Correct |
93 ms |
2256 KB |
Output is correct |
76 |
Correct |
107 ms |
2368 KB |
Output is correct |
77 |
Correct |
92 ms |
2388 KB |
Output is correct |
78 |
Correct |
93 ms |
2368 KB |
Output is correct |
79 |
Correct |
93 ms |
2352 KB |
Output is correct |
80 |
Correct |
97 ms |
2368 KB |
Output is correct |
81 |
Correct |
90 ms |
2368 KB |
Output is correct |
82 |
Correct |
93 ms |
2260 KB |
Output is correct |
83 |
Correct |
90 ms |
2260 KB |
Output is correct |
84 |
Correct |
94 ms |
2364 KB |
Output is correct |
85 |
Correct |
97 ms |
2368 KB |
Output is correct |
86 |
Correct |
99 ms |
2380 KB |
Output is correct |
87 |
Correct |
91 ms |
2364 KB |
Output is correct |
88 |
Correct |
89 ms |
2260 KB |
Output is correct |
89 |
Correct |
90 ms |
2364 KB |
Output is correct |
90 |
Correct |
89 ms |
2364 KB |
Output is correct |