#include <iostream>
using namespace std;
int N, M, ans;
char a[3010][3010];
int dp[3010][3010][3];
bool ver(int x, int y) {
return a[x-1][y]=='R' && a[x][y]=='G' && a[x+1][y]=='W';
}
bool hor(int x, int y) {
return a[x][y-1]=='R' && a[x][y]=='G' && a[x][y+1]=='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 i=1; i<=N; i++) {
for(int j=M; j>=1; j--) {
dp[i][j][0] = max(dp[i-1][j+1][0], max(dp[i-1][j+1][1], dp[i-1][j+1][2]));
dp[i][j][1] = (!ver(i,j) ? int(-1e9) : 1 + max(dp[i-1][j+1][0], dp[i-1][j+1][1]));
dp[i][j][2] = (!hor(i,j) ? int(-1e9) : 1 + max(dp[i-1][j+1][0], dp[i-1][j+1][2]));
}
}
for(int i=1; i<=N; i++) {
for(int j=1; j<=M; j++) {
if (i==N || j==1) {
ans += max(dp[i][j][0], max(dp[i][j][1], dp[i][j][2]));
}
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2492 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2496 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2492 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2492 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2496 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2492 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4544 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4540 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4540 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4540 KB |
Output is correct |
40 |
Correct |
1 ms |
4448 KB |
Output is correct |
41 |
Correct |
1 ms |
4448 KB |
Output is correct |
42 |
Correct |
1 ms |
4448 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4448 KB |
Output is correct |
46 |
Correct |
1 ms |
4448 KB |
Output is correct |
47 |
Correct |
1 ms |
4448 KB |
Output is correct |
48 |
Correct |
1 ms |
4448 KB |
Output is correct |
49 |
Correct |
1 ms |
4448 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4448 KB |
Output is correct |
52 |
Correct |
1 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2492 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2496 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2492 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4544 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4540 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4540 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
1 ms |
4540 KB |
Output is correct |
40 |
Correct |
1 ms |
4448 KB |
Output is correct |
41 |
Correct |
1 ms |
4448 KB |
Output is correct |
42 |
Correct |
1 ms |
4448 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4444 KB |
Output is correct |
45 |
Correct |
1 ms |
4448 KB |
Output is correct |
46 |
Correct |
1 ms |
4448 KB |
Output is correct |
47 |
Correct |
1 ms |
4448 KB |
Output is correct |
48 |
Correct |
1 ms |
4448 KB |
Output is correct |
49 |
Correct |
1 ms |
4448 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4448 KB |
Output is correct |
52 |
Correct |
1 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
54 |
Correct |
1 ms |
2396 KB |
Output is correct |
55 |
Correct |
16 ms |
115376 KB |
Output is correct |
56 |
Correct |
2 ms |
4696 KB |
Output is correct |
57 |
Correct |
13 ms |
80496 KB |
Output is correct |
58 |
Correct |
49 ms |
44372 KB |
Output is correct |
59 |
Correct |
399 ms |
124276 KB |
Output is correct |
60 |
Correct |
416 ms |
124312 KB |
Output is correct |
61 |
Correct |
398 ms |
124276 KB |
Output is correct |
62 |
Correct |
1 ms |
2396 KB |
Output is correct |
63 |
Correct |
388 ms |
123988 KB |
Output is correct |
64 |
Correct |
329 ms |
124184 KB |
Output is correct |
65 |
Correct |
352 ms |
124192 KB |
Output is correct |
66 |
Correct |
352 ms |
124200 KB |
Output is correct |
67 |
Correct |
333 ms |
124332 KB |
Output is correct |
68 |
Correct |
338 ms |
124648 KB |
Output is correct |
69 |
Correct |
361 ms |
124180 KB |
Output is correct |
70 |
Correct |
43 ms |
44372 KB |
Output is correct |
71 |
Correct |
41 ms |
44372 KB |
Output is correct |
72 |
Correct |
55 ms |
44416 KB |
Output is correct |
73 |
Correct |
41 ms |
44372 KB |
Output is correct |
74 |
Correct |
42 ms |
44552 KB |
Output is correct |
75 |
Correct |
42 ms |
44372 KB |
Output is correct |
76 |
Correct |
52 ms |
44372 KB |
Output is correct |
77 |
Correct |
46 ms |
44628 KB |
Output is correct |
78 |
Correct |
42 ms |
44372 KB |
Output is correct |
79 |
Correct |
45 ms |
44372 KB |
Output is correct |
80 |
Correct |
42 ms |
44456 KB |
Output is correct |
81 |
Correct |
42 ms |
44408 KB |
Output is correct |
82 |
Correct |
43 ms |
44480 KB |
Output is correct |
83 |
Correct |
45 ms |
44372 KB |
Output is correct |
84 |
Correct |
47 ms |
44628 KB |
Output is correct |
85 |
Correct |
43 ms |
44428 KB |
Output is correct |
86 |
Correct |
43 ms |
44496 KB |
Output is correct |
87 |
Correct |
44 ms |
44440 KB |
Output is correct |
88 |
Correct |
51 ms |
44372 KB |
Output is correct |
89 |
Correct |
45 ms |
44372 KB |
Output is correct |
90 |
Correct |
42 ms |
44424 KB |
Output is correct |