#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ff first
#define ss second
#define N 3005
#define MOD 1000000007
char c[N][N];
bool in[N][2];
int dp[N][4];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin>>n>>m;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
cin>>c[i][j];
}
}
int res = 0;
for(int s = 2; s <= n + m; ++s){
int l = max(1, s - m);
int r = min(n, s - 1);
for(int i = l; i <= r; ++i){
if(c[i][s - i] == 'R' && c[i][s - i + 1] == 'G' && c[i][s - i + 2] == 'W'){
in[i][0] = 1;
}
if(c[i][s - i] == 'R' && c[i + 1][s - i] == 'G' && c[i + 2][s - i] == 'W'){
in[i][1] = 1;
}
}
memset(dp[l - 1], 0, sizeof dp[l - 1]);
for(int i = l; i <= r; ++i){
memset(dp[i], 0, sizeof dp[i]);
for(int j = 0; j < 4; ++j)
dp[i][j / 2] = max(dp[i][j / 2], dp[i - 1][j]);
if(in[i][1]){
for(int j = 0; j < 4; ++j)
dp[i][j / 2 + 2] = max(dp[i][j / 2 + 2], dp[i - 1][j] + 1);
}
if(in[i][0])
dp[i][0] = max(dp[i - 1][0] + 1, dp[i][0]);
}
res += max(max(dp[r][0], dp[r][1]), max(dp[r][2], dp[r][3]));
for(int i = l; i <= r; ++i){
in[i][0] = in[i][1] = 0;
}
}
cout<<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
380 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
508 KB |
Output is correct |
23 |
Correct |
5 ms |
380 KB |
Output is correct |
24 |
Correct |
5 ms |
380 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
380 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
5 ms |
376 KB |
Output is correct |
41 |
Correct |
5 ms |
376 KB |
Output is correct |
42 |
Correct |
5 ms |
376 KB |
Output is correct |
43 |
Correct |
5 ms |
376 KB |
Output is correct |
44 |
Correct |
5 ms |
376 KB |
Output is correct |
45 |
Correct |
5 ms |
376 KB |
Output is correct |
46 |
Correct |
5 ms |
376 KB |
Output is correct |
47 |
Correct |
5 ms |
376 KB |
Output is correct |
48 |
Correct |
5 ms |
376 KB |
Output is correct |
49 |
Correct |
5 ms |
376 KB |
Output is correct |
50 |
Correct |
5 ms |
376 KB |
Output is correct |
51 |
Correct |
5 ms |
376 KB |
Output is correct |
52 |
Correct |
5 ms |
376 KB |
Output is correct |
53 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
4 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
380 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
508 KB |
Output is correct |
23 |
Correct |
5 ms |
380 KB |
Output is correct |
24 |
Correct |
5 ms |
380 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
380 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
5 ms |
376 KB |
Output is correct |
37 |
Correct |
5 ms |
376 KB |
Output is correct |
38 |
Correct |
5 ms |
376 KB |
Output is correct |
39 |
Correct |
5 ms |
376 KB |
Output is correct |
40 |
Correct |
5 ms |
376 KB |
Output is correct |
41 |
Correct |
5 ms |
376 KB |
Output is correct |
42 |
Correct |
5 ms |
376 KB |
Output is correct |
43 |
Correct |
5 ms |
376 KB |
Output is correct |
44 |
Correct |
5 ms |
376 KB |
Output is correct |
45 |
Correct |
5 ms |
376 KB |
Output is correct |
46 |
Correct |
5 ms |
376 KB |
Output is correct |
47 |
Correct |
5 ms |
376 KB |
Output is correct |
48 |
Correct |
5 ms |
376 KB |
Output is correct |
49 |
Correct |
5 ms |
376 KB |
Output is correct |
50 |
Correct |
5 ms |
376 KB |
Output is correct |
51 |
Correct |
5 ms |
376 KB |
Output is correct |
52 |
Correct |
5 ms |
376 KB |
Output is correct |
53 |
Correct |
5 ms |
376 KB |
Output is correct |
54 |
Correct |
5 ms |
376 KB |
Output is correct |
55 |
Correct |
9 ms |
9208 KB |
Output is correct |
56 |
Correct |
5 ms |
376 KB |
Output is correct |
57 |
Correct |
8 ms |
6264 KB |
Output is correct |
58 |
Correct |
35 ms |
3320 KB |
Output is correct |
59 |
Correct |
282 ms |
9316 KB |
Output is correct |
60 |
Correct |
273 ms |
9208 KB |
Output is correct |
61 |
Correct |
289 ms |
9336 KB |
Output is correct |
62 |
Correct |
5 ms |
376 KB |
Output is correct |
63 |
Correct |
269 ms |
9208 KB |
Output is correct |
64 |
Correct |
255 ms |
9336 KB |
Output is correct |
65 |
Correct |
265 ms |
9372 KB |
Output is correct |
66 |
Correct |
256 ms |
9212 KB |
Output is correct |
67 |
Correct |
248 ms |
9336 KB |
Output is correct |
68 |
Correct |
244 ms |
9208 KB |
Output is correct |
69 |
Correct |
247 ms |
9208 KB |
Output is correct |
70 |
Correct |
29 ms |
3320 KB |
Output is correct |
71 |
Correct |
29 ms |
3320 KB |
Output is correct |
72 |
Correct |
30 ms |
3320 KB |
Output is correct |
73 |
Correct |
30 ms |
3324 KB |
Output is correct |
74 |
Correct |
32 ms |
3320 KB |
Output is correct |
75 |
Correct |
29 ms |
3320 KB |
Output is correct |
76 |
Correct |
31 ms |
3320 KB |
Output is correct |
77 |
Correct |
30 ms |
3320 KB |
Output is correct |
78 |
Correct |
31 ms |
3320 KB |
Output is correct |
79 |
Correct |
30 ms |
3320 KB |
Output is correct |
80 |
Correct |
30 ms |
3320 KB |
Output is correct |
81 |
Correct |
30 ms |
3320 KB |
Output is correct |
82 |
Correct |
31 ms |
3320 KB |
Output is correct |
83 |
Correct |
30 ms |
3320 KB |
Output is correct |
84 |
Correct |
33 ms |
3320 KB |
Output is correct |
85 |
Correct |
30 ms |
3320 KB |
Output is correct |
86 |
Correct |
30 ms |
3320 KB |
Output is correct |
87 |
Correct |
30 ms |
3320 KB |
Output is correct |
88 |
Correct |
31 ms |
3320 KB |
Output is correct |
89 |
Correct |
30 ms |
3320 KB |
Output is correct |
90 |
Correct |
29 ms |
3320 KB |
Output is correct |