#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int n, m, d[N][N][4], r;
char a[N][N];
int v(int x, int y, int d){
return
a[x][y] == 'R' &&
a[x + d][y + !d] == 'G' &&
a[x + 2 * d][y + 2 * !d] == 'W';
}
int main(){
cin >> n >> m;
for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) cin >> a[i][j];
for(int t = 2; t <= n + m; t++){
int cm = 0;
for(int i = t - 1, j; i >= 1; i--){
j = t - i;
if(j < 1 || j > m || i < 1 || i > n) continue;
int *c = d[i][j], *p = d[i + 1][j - 1];
c[0] = max(p[0] + v(i, j, 1), p[1]);
c[1] = max(p[2], p[3]);
if(v(i, j, 0)){
c[2] = max(p[0], p[1]) + 1;
c[3] = max(p[2], p[3]) + 1;
}
cm = max(cm, *max_element(c, c + 4));
}
r += cm;
}
cout << r;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
460 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
584 KB |
Output is correct |
5 |
Correct |
3 ms |
584 KB |
Output is correct |
6 |
Correct |
2 ms |
584 KB |
Output is correct |
7 |
Correct |
3 ms |
584 KB |
Output is correct |
8 |
Correct |
3 ms |
584 KB |
Output is correct |
9 |
Correct |
3 ms |
584 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
636 KB |
Output is correct |
12 |
Correct |
3 ms |
640 KB |
Output is correct |
13 |
Correct |
3 ms |
644 KB |
Output is correct |
14 |
Correct |
3 ms |
644 KB |
Output is correct |
15 |
Correct |
2 ms |
652 KB |
Output is correct |
16 |
Correct |
3 ms |
656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
460 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
584 KB |
Output is correct |
5 |
Correct |
3 ms |
584 KB |
Output is correct |
6 |
Correct |
2 ms |
584 KB |
Output is correct |
7 |
Correct |
3 ms |
584 KB |
Output is correct |
8 |
Correct |
3 ms |
584 KB |
Output is correct |
9 |
Correct |
3 ms |
584 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
636 KB |
Output is correct |
12 |
Correct |
3 ms |
640 KB |
Output is correct |
13 |
Correct |
3 ms |
644 KB |
Output is correct |
14 |
Correct |
3 ms |
644 KB |
Output is correct |
15 |
Correct |
2 ms |
652 KB |
Output is correct |
16 |
Correct |
3 ms |
656 KB |
Output is correct |
17 |
Correct |
4 ms |
660 KB |
Output is correct |
18 |
Correct |
2 ms |
664 KB |
Output is correct |
19 |
Correct |
4 ms |
668 KB |
Output is correct |
20 |
Correct |
4 ms |
672 KB |
Output is correct |
21 |
Correct |
2 ms |
676 KB |
Output is correct |
22 |
Correct |
3 ms |
704 KB |
Output is correct |
23 |
Correct |
3 ms |
708 KB |
Output is correct |
24 |
Correct |
4 ms |
712 KB |
Output is correct |
25 |
Correct |
2 ms |
720 KB |
Output is correct |
26 |
Correct |
4 ms |
720 KB |
Output is correct |
27 |
Correct |
4 ms |
724 KB |
Output is correct |
28 |
Correct |
2 ms |
728 KB |
Output is correct |
29 |
Correct |
3 ms |
732 KB |
Output is correct |
30 |
Correct |
4 ms |
780 KB |
Output is correct |
31 |
Correct |
3 ms |
780 KB |
Output is correct |
32 |
Correct |
4 ms |
780 KB |
Output is correct |
33 |
Correct |
3 ms |
780 KB |
Output is correct |
34 |
Correct |
3 ms |
780 KB |
Output is correct |
35 |
Correct |
4 ms |
780 KB |
Output is correct |
36 |
Correct |
2 ms |
780 KB |
Output is correct |
37 |
Correct |
3 ms |
780 KB |
Output is correct |
38 |
Correct |
3 ms |
780 KB |
Output is correct |
39 |
Correct |
2 ms |
816 KB |
Output is correct |
40 |
Correct |
3 ms |
816 KB |
Output is correct |
41 |
Correct |
3 ms |
816 KB |
Output is correct |
42 |
Correct |
3 ms |
816 KB |
Output is correct |
43 |
Correct |
3 ms |
816 KB |
Output is correct |
44 |
Correct |
3 ms |
816 KB |
Output is correct |
45 |
Correct |
3 ms |
816 KB |
Output is correct |
46 |
Correct |
3 ms |
816 KB |
Output is correct |
47 |
Correct |
3 ms |
816 KB |
Output is correct |
48 |
Correct |
2 ms |
816 KB |
Output is correct |
49 |
Correct |
3 ms |
816 KB |
Output is correct |
50 |
Correct |
4 ms |
820 KB |
Output is correct |
51 |
Correct |
4 ms |
820 KB |
Output is correct |
52 |
Correct |
4 ms |
868 KB |
Output is correct |
53 |
Correct |
3 ms |
920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
460 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
584 KB |
Output is correct |
5 |
Correct |
3 ms |
584 KB |
Output is correct |
6 |
Correct |
2 ms |
584 KB |
Output is correct |
7 |
Correct |
3 ms |
584 KB |
Output is correct |
8 |
Correct |
3 ms |
584 KB |
Output is correct |
9 |
Correct |
3 ms |
584 KB |
Output is correct |
10 |
Correct |
3 ms |
632 KB |
Output is correct |
11 |
Correct |
3 ms |
636 KB |
Output is correct |
12 |
Correct |
3 ms |
640 KB |
Output is correct |
13 |
Correct |
3 ms |
644 KB |
Output is correct |
14 |
Correct |
3 ms |
644 KB |
Output is correct |
15 |
Correct |
2 ms |
652 KB |
Output is correct |
16 |
Correct |
3 ms |
656 KB |
Output is correct |
17 |
Correct |
4 ms |
660 KB |
Output is correct |
18 |
Correct |
2 ms |
664 KB |
Output is correct |
19 |
Correct |
4 ms |
668 KB |
Output is correct |
20 |
Correct |
4 ms |
672 KB |
Output is correct |
21 |
Correct |
2 ms |
676 KB |
Output is correct |
22 |
Correct |
3 ms |
704 KB |
Output is correct |
23 |
Correct |
3 ms |
708 KB |
Output is correct |
24 |
Correct |
4 ms |
712 KB |
Output is correct |
25 |
Correct |
2 ms |
720 KB |
Output is correct |
26 |
Correct |
4 ms |
720 KB |
Output is correct |
27 |
Correct |
4 ms |
724 KB |
Output is correct |
28 |
Correct |
2 ms |
728 KB |
Output is correct |
29 |
Correct |
3 ms |
732 KB |
Output is correct |
30 |
Correct |
4 ms |
780 KB |
Output is correct |
31 |
Correct |
3 ms |
780 KB |
Output is correct |
32 |
Correct |
4 ms |
780 KB |
Output is correct |
33 |
Correct |
3 ms |
780 KB |
Output is correct |
34 |
Correct |
3 ms |
780 KB |
Output is correct |
35 |
Correct |
4 ms |
780 KB |
Output is correct |
36 |
Correct |
2 ms |
780 KB |
Output is correct |
37 |
Correct |
3 ms |
780 KB |
Output is correct |
38 |
Correct |
3 ms |
780 KB |
Output is correct |
39 |
Correct |
2 ms |
816 KB |
Output is correct |
40 |
Correct |
3 ms |
816 KB |
Output is correct |
41 |
Correct |
3 ms |
816 KB |
Output is correct |
42 |
Correct |
3 ms |
816 KB |
Output is correct |
43 |
Correct |
3 ms |
816 KB |
Output is correct |
44 |
Correct |
3 ms |
816 KB |
Output is correct |
45 |
Correct |
3 ms |
816 KB |
Output is correct |
46 |
Correct |
3 ms |
816 KB |
Output is correct |
47 |
Correct |
3 ms |
816 KB |
Output is correct |
48 |
Correct |
2 ms |
816 KB |
Output is correct |
49 |
Correct |
3 ms |
816 KB |
Output is correct |
50 |
Correct |
4 ms |
820 KB |
Output is correct |
51 |
Correct |
4 ms |
820 KB |
Output is correct |
52 |
Correct |
4 ms |
868 KB |
Output is correct |
53 |
Correct |
3 ms |
920 KB |
Output is correct |
54 |
Correct |
12 ms |
920 KB |
Output is correct |
55 |
Correct |
30 ms |
21952 KB |
Output is correct |
56 |
Correct |
14 ms |
21952 KB |
Output is correct |
57 |
Correct |
21 ms |
21952 KB |
Output is correct |
58 |
Correct |
170 ms |
24496 KB |
Output is correct |
59 |
Correct |
1073 ms |
160768 KB |
Output is correct |
60 |
Correct |
1111 ms |
169580 KB |
Output is correct |
61 |
Correct |
1122 ms |
178460 KB |
Output is correct |
62 |
Correct |
9 ms |
178460 KB |
Output is correct |
63 |
Correct |
1223 ms |
186956 KB |
Output is correct |
64 |
Correct |
1060 ms |
195732 KB |
Output is correct |
65 |
Correct |
1177 ms |
204592 KB |
Output is correct |
66 |
Correct |
1161 ms |
213216 KB |
Output is correct |
67 |
Correct |
1119 ms |
221808 KB |
Output is correct |
68 |
Correct |
1020 ms |
230200 KB |
Output is correct |
69 |
Correct |
1112 ms |
238604 KB |
Output is correct |
70 |
Correct |
113 ms |
238604 KB |
Output is correct |
71 |
Correct |
172 ms |
238604 KB |
Output is correct |
72 |
Correct |
123 ms |
238604 KB |
Output is correct |
73 |
Correct |
150 ms |
238604 KB |
Output is correct |
74 |
Correct |
155 ms |
238604 KB |
Output is correct |
75 |
Correct |
139 ms |
238604 KB |
Output is correct |
76 |
Correct |
120 ms |
238604 KB |
Output is correct |
77 |
Correct |
170 ms |
238604 KB |
Output is correct |
78 |
Correct |
112 ms |
238604 KB |
Output is correct |
79 |
Correct |
132 ms |
238604 KB |
Output is correct |
80 |
Correct |
171 ms |
238604 KB |
Output is correct |
81 |
Correct |
110 ms |
238604 KB |
Output is correct |
82 |
Correct |
111 ms |
238604 KB |
Output is correct |
83 |
Correct |
132 ms |
238604 KB |
Output is correct |
84 |
Correct |
129 ms |
238604 KB |
Output is correct |
85 |
Correct |
133 ms |
238604 KB |
Output is correct |
86 |
Correct |
132 ms |
238604 KB |
Output is correct |
87 |
Correct |
118 ms |
238604 KB |
Output is correct |
88 |
Correct |
113 ms |
238604 KB |
Output is correct |
89 |
Correct |
115 ms |
238604 KB |
Output is correct |
90 |
Correct |
129 ms |
238604 KB |
Output is correct |