#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN = 3005, M = 1e9+7;
int n, m, dp[3][mxN], ans = 0;
string s[mxN];
inline bool c(int x, int y, char c){
return x>=0&&x<n&&y>=0&&y<m&&s[x][y]==c;
}
int main(){
#ifdef _DEBUG
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
cin >> n >> m;
for(int i = 0; i<n; ++i){
cin >> s[i];
}
for(int i = 0; i<n+m-3; ++i){
int border = min(m, i+2);
for(int j = 0; j<border; ++j){
dp[0][j+1] = max(dp[0][j], max(dp[1][j], dp[2][j]));
if(c(i-j+1, j-1, 'R') && c(i-j+1, j, 'G') && c(i-j+1, j+1, 'W')){
dp[1][j+1] = max(dp[0][j], dp[1][j])+1;
}else{
dp[1][j+1] = 0;
}
if(c(i-j, j, 'R') && c(i-j+1, j, 'G') && c(i-j+2, j, 'W')){
dp[2][j+1] = max(dp[0][j], dp[2][j])+1;
}else{
dp[2][j+1] = 0;
}
}
ans += max(dp[0][border], max(dp[1][border], dp[2][border]));
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
404 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
412 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
408 KB |
Output is correct |
7 |
Correct |
1 ms |
408 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
408 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
404 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
412 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
408 KB |
Output is correct |
7 |
Correct |
1 ms |
408 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
408 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
408 KB |
Output is correct |
22 |
Correct |
0 ms |
404 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
400 KB |
Output is correct |
26 |
Correct |
0 ms |
404 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
408 KB |
Output is correct |
36 |
Correct |
0 ms |
408 KB |
Output is correct |
37 |
Correct |
0 ms |
416 KB |
Output is correct |
38 |
Correct |
0 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
412 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
0 ms |
332 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
408 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
0 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
0 ms |
332 KB |
Output is correct |
52 |
Correct |
0 ms |
332 KB |
Output is correct |
53 |
Correct |
0 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
404 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
412 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
408 KB |
Output is correct |
7 |
Correct |
1 ms |
408 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
408 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
408 KB |
Output is correct |
22 |
Correct |
0 ms |
404 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
400 KB |
Output is correct |
26 |
Correct |
0 ms |
404 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
408 KB |
Output is correct |
36 |
Correct |
0 ms |
408 KB |
Output is correct |
37 |
Correct |
0 ms |
416 KB |
Output is correct |
38 |
Correct |
0 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
412 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
0 ms |
332 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
0 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
408 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
0 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
0 ms |
332 KB |
Output is correct |
52 |
Correct |
0 ms |
332 KB |
Output is correct |
53 |
Correct |
0 ms |
408 KB |
Output is correct |
54 |
Correct |
23 ms |
400 KB |
Output is correct |
55 |
Correct |
1 ms |
332 KB |
Output is correct |
56 |
Correct |
22 ms |
480 KB |
Output is correct |
57 |
Correct |
1 ms |
416 KB |
Output is correct |
58 |
Correct |
15 ms |
2468 KB |
Output is correct |
59 |
Correct |
156 ms |
18932 KB |
Output is correct |
60 |
Correct |
155 ms |
18972 KB |
Output is correct |
61 |
Correct |
155 ms |
18964 KB |
Output is correct |
62 |
Correct |
21 ms |
408 KB |
Output is correct |
63 |
Correct |
148 ms |
18556 KB |
Output is correct |
64 |
Correct |
107 ms |
18860 KB |
Output is correct |
65 |
Correct |
138 ms |
18968 KB |
Output is correct |
66 |
Correct |
100 ms |
18884 KB |
Output is correct |
67 |
Correct |
99 ms |
18968 KB |
Output is correct |
68 |
Correct |
102 ms |
18884 KB |
Output is correct |
69 |
Correct |
115 ms |
18960 KB |
Output is correct |
70 |
Correct |
10 ms |
2436 KB |
Output is correct |
71 |
Correct |
10 ms |
2440 KB |
Output is correct |
72 |
Correct |
12 ms |
2444 KB |
Output is correct |
73 |
Correct |
15 ms |
2440 KB |
Output is correct |
74 |
Correct |
13 ms |
2456 KB |
Output is correct |
75 |
Correct |
13 ms |
2444 KB |
Output is correct |
76 |
Correct |
12 ms |
2456 KB |
Output is correct |
77 |
Correct |
11 ms |
2332 KB |
Output is correct |
78 |
Correct |
10 ms |
2444 KB |
Output is correct |
79 |
Correct |
10 ms |
2372 KB |
Output is correct |
80 |
Correct |
11 ms |
2432 KB |
Output is correct |
81 |
Correct |
10 ms |
2448 KB |
Output is correct |
82 |
Correct |
10 ms |
2332 KB |
Output is correct |
83 |
Correct |
11 ms |
2444 KB |
Output is correct |
84 |
Correct |
10 ms |
2336 KB |
Output is correct |
85 |
Correct |
11 ms |
2372 KB |
Output is correct |
86 |
Correct |
10 ms |
2408 KB |
Output is correct |
87 |
Correct |
10 ms |
2416 KB |
Output is correct |
88 |
Correct |
12 ms |
2472 KB |
Output is correct |
89 |
Correct |
11 ms |
2352 KB |
Output is correct |
90 |
Correct |
10 ms |
2436 KB |
Output is correct |