#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e3 + 2;
const int inf = 2e9;
int mat[N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> c(n + m - 1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char ch; cin >> ch;
if (ch == 'R') mat[i][j] = 0;
if (ch == 'G') mat[i][j] = 1;
if (ch == 'W') mat[i][j] = 2;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int val = 0;
if (j < m - 2 && mat[i][j] == 0 && mat[i][j + 1] == 1 && mat[i][j + 2] == 2) val++;
if (i < n - 2 && mat[i][j] == 0 && mat[i + 1][j] == 1 && mat[i + 2][j] == 2) val += 2;
c[i + j].push_back(val);
}
}
int ans = 0;
for (auto v : c) {
int sz = v.size();
vector<vector<int>> dp(sz + 1, vector<int>(4, -inf));
dp[0][3] = 0;
for (int i = 0; i < sz; i++) {
for (int j = 0; j < 3; j++) smax(dp[i + 1][j + 1], dp[i][j]);
smax(dp[i + 1][3], dp[i][3]);
if (v[i] % 2 == 1) {
dp[i + 1][3] = max(dp[i][2], dp[i][3]) + 1;
}
if (v[i] / 2 == 1) {
dp[i + 1][0] = *max_element(dp[i].begin(), dp[i].end()) + 1;
}
}
ans += *max_element(dp[sz].begin(), dp[sz].end());
}
cout << ans << en;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
344 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 |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
324 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
328 KB |
Output is correct |
40 |
Correct |
1 ms |
324 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
344 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 |
328 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
324 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
328 KB |
Output is correct |
40 |
Correct |
1 ms |
324 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
1 ms |
324 KB |
Output is correct |
54 |
Correct |
2 ms |
472 KB |
Output is correct |
55 |
Correct |
6 ms |
12504 KB |
Output is correct |
56 |
Correct |
3 ms |
600 KB |
Output is correct |
57 |
Correct |
6 ms |
8532 KB |
Output is correct |
58 |
Correct |
92 ms |
14648 KB |
Output is correct |
59 |
Correct |
750 ms |
94272 KB |
Output is correct |
60 |
Correct |
737 ms |
94284 KB |
Output is correct |
61 |
Correct |
747 ms |
94160 KB |
Output is correct |
62 |
Correct |
1 ms |
472 KB |
Output is correct |
63 |
Correct |
736 ms |
92368 KB |
Output is correct |
64 |
Correct |
711 ms |
94180 KB |
Output is correct |
65 |
Correct |
676 ms |
94236 KB |
Output is correct |
66 |
Correct |
629 ms |
94160 KB |
Output is correct |
67 |
Correct |
668 ms |
94240 KB |
Output is correct |
68 |
Correct |
694 ms |
94188 KB |
Output is correct |
69 |
Correct |
635 ms |
94160 KB |
Output is correct |
70 |
Correct |
70 ms |
14680 KB |
Output is correct |
71 |
Correct |
68 ms |
14680 KB |
Output is correct |
72 |
Correct |
67 ms |
14656 KB |
Output is correct |
73 |
Correct |
84 ms |
14664 KB |
Output is correct |
74 |
Correct |
92 ms |
14656 KB |
Output is correct |
75 |
Correct |
68 ms |
14668 KB |
Output is correct |
76 |
Correct |
69 ms |
14800 KB |
Output is correct |
77 |
Correct |
69 ms |
14668 KB |
Output is correct |
78 |
Correct |
68 ms |
14672 KB |
Output is correct |
79 |
Correct |
67 ms |
14628 KB |
Output is correct |
80 |
Correct |
73 ms |
14660 KB |
Output is correct |
81 |
Correct |
72 ms |
14680 KB |
Output is correct |
82 |
Correct |
68 ms |
14648 KB |
Output is correct |
83 |
Correct |
67 ms |
14684 KB |
Output is correct |
84 |
Correct |
69 ms |
14668 KB |
Output is correct |
85 |
Correct |
67 ms |
14564 KB |
Output is correct |
86 |
Correct |
68 ms |
14668 KB |
Output is correct |
87 |
Correct |
69 ms |
14668 KB |
Output is correct |
88 |
Correct |
76 ms |
14596 KB |
Output is correct |
89 |
Correct |
87 ms |
14680 KB |
Output is correct |
90 |
Correct |
70 ms |
14732 KB |
Output is correct |