#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
const int nmax = 3007;
char mat[nmax][nmax];
int jos[nmax][nmax], dr[nmax][nmax], dp[nmax][nmax][3];
int32_t main() {
int n, m, ans = 0;
cin >> n >> m;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
cin >> mat[i][j];
}
}
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
if(mat[i][j - 1] == 'R' && mat[i][j] == 'G' && mat[i][j + 1] == 'W') {
dr[i][j] = 1;
}
if(mat[i - 1][j] == 'R' && mat[i][j] == 'G' && mat[i + 1][j] == 'W') {
jos[i][j] = 1;
}
}
}
int l = 1, c = 1, x = n + m;
while(x > 1) {
int i = l, j = c;
dp[i][j][0] = 0;
dp[i][j][1] = dr[i][j];
dp[i][j][2] = jos[i][j];
i --;
j ++;
while(j <= m && i > 0) {
for(int d = 0; d <= 2; d ++) {
dp[i][j][0] = max(dp[i][j][0], dp[i + 1][j - 1][d]);
}
dp[i][j][1] = max(dp[i + 1][j - 1][1], dp[i + 1][j - 1][0]) + dr[i][j];
dp[i][j][2] = max(dp[i + 1][j - 1][2], dp[i + 1][j - 1][0]) + jos[i][j];
i --;
j ++;
}
i ++;
j --;
ans = ans + max({dp[i][j][1], dp[i][j][2], dp[i][j][0]});
l ++;
if(l > n) {
l = n;
c ++;
}
x --;
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
0 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
0 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
436 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
472 KB |
Output is correct |
30 |
Correct |
1 ms |
312 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
308 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
440 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
436 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
0 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
0 ms |
468 KB |
Output is correct |
53 |
Correct |
1 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
308 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 |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
0 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
436 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
472 KB |
Output is correct |
30 |
Correct |
1 ms |
312 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
308 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
440 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
436 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
0 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
0 ms |
468 KB |
Output is correct |
53 |
Correct |
1 ms |
436 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
12 ms |
21844 KB |
Output is correct |
56 |
Correct |
1 ms |
596 KB |
Output is correct |
57 |
Correct |
13 ms |
24532 KB |
Output is correct |
58 |
Correct |
83 ms |
35416 KB |
Output is correct |
59 |
Correct |
800 ms |
194512 KB |
Output is correct |
60 |
Correct |
762 ms |
194400 KB |
Output is correct |
61 |
Correct |
752 ms |
194340 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
744 ms |
194136 KB |
Output is correct |
64 |
Correct |
699 ms |
194352 KB |
Output is correct |
65 |
Correct |
704 ms |
194344 KB |
Output is correct |
66 |
Correct |
728 ms |
194380 KB |
Output is correct |
67 |
Correct |
643 ms |
139764 KB |
Output is correct |
68 |
Correct |
630 ms |
139796 KB |
Output is correct |
69 |
Correct |
653 ms |
149656 KB |
Output is correct |
70 |
Correct |
70 ms |
35788 KB |
Output is correct |
71 |
Correct |
69 ms |
35916 KB |
Output is correct |
72 |
Correct |
72 ms |
35724 KB |
Output is correct |
73 |
Correct |
71 ms |
35812 KB |
Output is correct |
74 |
Correct |
70 ms |
35744 KB |
Output is correct |
75 |
Correct |
71 ms |
35776 KB |
Output is correct |
76 |
Correct |
72 ms |
35836 KB |
Output is correct |
77 |
Correct |
76 ms |
35772 KB |
Output is correct |
78 |
Correct |
70 ms |
35712 KB |
Output is correct |
79 |
Correct |
69 ms |
35800 KB |
Output is correct |
80 |
Correct |
70 ms |
35720 KB |
Output is correct |
81 |
Correct |
69 ms |
35788 KB |
Output is correct |
82 |
Correct |
71 ms |
35812 KB |
Output is correct |
83 |
Correct |
72 ms |
35780 KB |
Output is correct |
84 |
Correct |
73 ms |
35736 KB |
Output is correct |
85 |
Correct |
69 ms |
35828 KB |
Output is correct |
86 |
Correct |
70 ms |
35716 KB |
Output is correct |
87 |
Correct |
70 ms |
35788 KB |
Output is correct |
88 |
Correct |
70 ms |
35776 KB |
Output is correct |
89 |
Correct |
69 ms |
35732 KB |
Output is correct |
90 |
Correct |
70 ms |
35724 KB |
Output is correct |