#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
#define pA first
#define pB second
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define vi vector<int>
#define pb push_back
int main() {
int n, m; cin >> n >> m;
char A[n][m]; F0R(i, n) F0R(j, m) cin >> A[i][j];
int ans = 0;
int dp[n+1][3];
F0R(diagonal, n+m) {
F0R(i, n+1) F0R(j, 3) dp[i][j] = 0;
int lastI = -1;
F0R(i, n) {
int j = diagonal-i;
if (j < 0 || j >= m) continue;
lastI = i;
int right = 0;
if (j+2<m&& A[i][j] == 'R' && A[i][j+1] == 'G' && A[i][j+2] == 'W') right=1;
int down = 0;
if (i+2<n&& A[i][j] == 'R' && A[i+1][j] == 'G' && A[i+2][j] == 'W') down=1;
dp[i+1][0] = max(dp[i][0] + right, dp[i][1]);
dp[i+1][1] = dp[i][2];
dp[i+1][2] = max(dp[i][0], max(dp[i][1], dp[i][2])) + down;
}
lastI++;
// cout << diagonal << " " << max(dp[lastI][0], max(dp[lastI][1], dp[lastI][2])) << endl;
ans += max(dp[lastI][0], max(dp[lastI][1], dp[lastI][2]));
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
128 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
128 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
4 ms |
256 KB |
Output is correct |
22 |
Correct |
5 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
256 KB |
Output is correct |
24 |
Correct |
4 ms |
256 KB |
Output is correct |
25 |
Correct |
4 ms |
256 KB |
Output is correct |
26 |
Correct |
4 ms |
256 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
256 KB |
Output is correct |
29 |
Correct |
4 ms |
256 KB |
Output is correct |
30 |
Correct |
4 ms |
256 KB |
Output is correct |
31 |
Correct |
5 ms |
256 KB |
Output is correct |
32 |
Correct |
4 ms |
256 KB |
Output is correct |
33 |
Correct |
5 ms |
256 KB |
Output is correct |
34 |
Correct |
4 ms |
256 KB |
Output is correct |
35 |
Correct |
4 ms |
256 KB |
Output is correct |
36 |
Correct |
4 ms |
256 KB |
Output is correct |
37 |
Correct |
4 ms |
256 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
5 ms |
384 KB |
Output is correct |
40 |
Correct |
4 ms |
256 KB |
Output is correct |
41 |
Correct |
4 ms |
256 KB |
Output is correct |
42 |
Correct |
5 ms |
256 KB |
Output is correct |
43 |
Correct |
4 ms |
256 KB |
Output is correct |
44 |
Correct |
4 ms |
256 KB |
Output is correct |
45 |
Correct |
5 ms |
256 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
4 ms |
256 KB |
Output is correct |
48 |
Correct |
4 ms |
256 KB |
Output is correct |
49 |
Correct |
5 ms |
256 KB |
Output is correct |
50 |
Correct |
4 ms |
256 KB |
Output is correct |
51 |
Correct |
4 ms |
256 KB |
Output is correct |
52 |
Correct |
4 ms |
256 KB |
Output is correct |
53 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
128 KB |
Output is correct |
13 |
Correct |
6 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
256 KB |
Output is correct |
17 |
Correct |
4 ms |
256 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
256 KB |
Output is correct |
21 |
Correct |
4 ms |
256 KB |
Output is correct |
22 |
Correct |
5 ms |
256 KB |
Output is correct |
23 |
Correct |
5 ms |
256 KB |
Output is correct |
24 |
Correct |
4 ms |
256 KB |
Output is correct |
25 |
Correct |
4 ms |
256 KB |
Output is correct |
26 |
Correct |
4 ms |
256 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
256 KB |
Output is correct |
29 |
Correct |
4 ms |
256 KB |
Output is correct |
30 |
Correct |
4 ms |
256 KB |
Output is correct |
31 |
Correct |
5 ms |
256 KB |
Output is correct |
32 |
Correct |
4 ms |
256 KB |
Output is correct |
33 |
Correct |
5 ms |
256 KB |
Output is correct |
34 |
Correct |
4 ms |
256 KB |
Output is correct |
35 |
Correct |
4 ms |
256 KB |
Output is correct |
36 |
Correct |
4 ms |
256 KB |
Output is correct |
37 |
Correct |
4 ms |
256 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
5 ms |
384 KB |
Output is correct |
40 |
Correct |
4 ms |
256 KB |
Output is correct |
41 |
Correct |
4 ms |
256 KB |
Output is correct |
42 |
Correct |
5 ms |
256 KB |
Output is correct |
43 |
Correct |
4 ms |
256 KB |
Output is correct |
44 |
Correct |
4 ms |
256 KB |
Output is correct |
45 |
Correct |
5 ms |
256 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
4 ms |
256 KB |
Output is correct |
48 |
Correct |
4 ms |
256 KB |
Output is correct |
49 |
Correct |
5 ms |
256 KB |
Output is correct |
50 |
Correct |
4 ms |
256 KB |
Output is correct |
51 |
Correct |
4 ms |
256 KB |
Output is correct |
52 |
Correct |
4 ms |
256 KB |
Output is correct |
53 |
Correct |
5 ms |
256 KB |
Output is correct |
54 |
Correct |
5 ms |
256 KB |
Output is correct |
55 |
Correct |
26 ms |
384 KB |
Output is correct |
56 |
Correct |
6 ms |
384 KB |
Output is correct |
57 |
Correct |
16 ms |
384 KB |
Output is correct |
58 |
Correct |
97 ms |
2296 KB |
Output is correct |
59 |
Correct |
855 ms |
17912 KB |
Output is correct |
60 |
Correct |
856 ms |
18092 KB |
Output is correct |
61 |
Correct |
855 ms |
18112 KB |
Output is correct |
62 |
Correct |
5 ms |
256 KB |
Output is correct |
63 |
Correct |
825 ms |
17400 KB |
Output is correct |
64 |
Correct |
803 ms |
17992 KB |
Output is correct |
65 |
Correct |
799 ms |
18040 KB |
Output is correct |
66 |
Correct |
799 ms |
18168 KB |
Output is correct |
67 |
Correct |
804 ms |
18168 KB |
Output is correct |
68 |
Correct |
801 ms |
18044 KB |
Output is correct |
69 |
Correct |
815 ms |
18044 KB |
Output is correct |
70 |
Correct |
91 ms |
2424 KB |
Output is correct |
71 |
Correct |
91 ms |
2272 KB |
Output is correct |
72 |
Correct |
93 ms |
2296 KB |
Output is correct |
73 |
Correct |
91 ms |
2296 KB |
Output is correct |
74 |
Correct |
91 ms |
2296 KB |
Output is correct |
75 |
Correct |
93 ms |
2296 KB |
Output is correct |
76 |
Correct |
91 ms |
2296 KB |
Output is correct |
77 |
Correct |
95 ms |
2296 KB |
Output is correct |
78 |
Correct |
94 ms |
2296 KB |
Output is correct |
79 |
Correct |
93 ms |
2272 KB |
Output is correct |
80 |
Correct |
92 ms |
2296 KB |
Output is correct |
81 |
Correct |
91 ms |
2296 KB |
Output is correct |
82 |
Correct |
95 ms |
2296 KB |
Output is correct |
83 |
Correct |
92 ms |
2296 KB |
Output is correct |
84 |
Correct |
93 ms |
2296 KB |
Output is correct |
85 |
Correct |
91 ms |
2296 KB |
Output is correct |
86 |
Correct |
94 ms |
2296 KB |
Output is correct |
87 |
Correct |
91 ms |
2296 KB |
Output is correct |
88 |
Correct |
91 ms |
2296 KB |
Output is correct |
89 |
Correct |
92 ms |
2296 KB |
Output is correct |
90 |
Correct |
91 ms |
2300 KB |
Output is correct |