/*
check for(ij)
*/
#include<bits/stdc++.h>
using namespace std;
const int N = (int)3e3 + 5;
int n, m, ans, dp[N][4];
char c[N][N];
bool validCell (int x, int y) { return x >= 1 && y >= 1 && x <= n && y <= m; }
bool downCheck (int x, int y) {
return validCell(x, y) && validCell(x + 1, y) && validCell(x + 2, y) && c[x][y] == 'R' && c[x + 1][y] == 'G' && c[x + 2][y] == 'W';
}
bool rightCheck (int x, int y) {
return validCell(x, y) && validCell(x, y + 1) && validCell(x, y + 2) && c[x][y] == 'R' && c[x][y + 1] == 'G' && c[x][y + 2] == 'W';
}
void update (int &_a, int _b) {
_a = max(_a, _b);
}
int main () {
// freopen("test.INP", "r", stdin);
// freopen("Seeht.OUT", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) cin >> c[i][j];
}
for (int ij = 2; ij <= n + m - 2; ++ij) {
memset(dp, 0, sizeof dp);
for (int i = max(1, ij - m); i <= min(n, ij - 1); ++i) {
int j = ij - i;
for (int mask = 0; mask < 4; ++mask) {
update(dp[i][mask >> 1], dp[i - 1][mask]);
if (downCheck(i, j) ) update(dp[i][(mask >> 1) | 2], dp[i - 1][mask] + 1);
}
if (rightCheck(i, j) ) update(dp[i][0], dp[i - 1][0] + 1);
}
ans += max(dp[ min(n, ij - 1) ][0], max(dp[ min(n, ij - 1) ][1], max(dp[ min(n, ij - 1) ][2], dp[ min(n, ij - 1) ][3]) ) );
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
380 KB |
Output is correct |
38 |
Correct |
2 ms |
380 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
3 ms |
376 KB |
Output is correct |
45 |
Correct |
3 ms |
380 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
2 ms |
420 KB |
Output is correct |
48 |
Correct |
2 ms |
380 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
53 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
380 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
2 ms |
380 KB |
Output is correct |
38 |
Correct |
2 ms |
380 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
3 ms |
376 KB |
Output is correct |
45 |
Correct |
3 ms |
380 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
2 ms |
420 KB |
Output is correct |
48 |
Correct |
2 ms |
380 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
53 |
Correct |
2 ms |
376 KB |
Output is correct |
54 |
Correct |
10 ms |
376 KB |
Output is correct |
55 |
Correct |
16 ms |
9208 KB |
Output is correct |
56 |
Correct |
10 ms |
376 KB |
Output is correct |
57 |
Correct |
12 ms |
6264 KB |
Output is correct |
58 |
Correct |
69 ms |
4344 KB |
Output is correct |
59 |
Correct |
622 ms |
18168 KB |
Output is correct |
60 |
Correct |
625 ms |
18040 KB |
Output is correct |
61 |
Correct |
644 ms |
18172 KB |
Output is correct |
62 |
Correct |
9 ms |
376 KB |
Output is correct |
63 |
Correct |
604 ms |
17784 KB |
Output is correct |
64 |
Correct |
554 ms |
18012 KB |
Output is correct |
65 |
Correct |
544 ms |
18040 KB |
Output is correct |
66 |
Correct |
559 ms |
18140 KB |
Output is correct |
67 |
Correct |
501 ms |
18040 KB |
Output is correct |
68 |
Correct |
514 ms |
18168 KB |
Output is correct |
69 |
Correct |
515 ms |
18040 KB |
Output is correct |
70 |
Correct |
58 ms |
4344 KB |
Output is correct |
71 |
Correct |
58 ms |
4344 KB |
Output is correct |
72 |
Correct |
60 ms |
4344 KB |
Output is correct |
73 |
Correct |
59 ms |
4344 KB |
Output is correct |
74 |
Correct |
59 ms |
4344 KB |
Output is correct |
75 |
Correct |
58 ms |
4344 KB |
Output is correct |
76 |
Correct |
58 ms |
4344 KB |
Output is correct |
77 |
Correct |
58 ms |
4344 KB |
Output is correct |
78 |
Correct |
58 ms |
4344 KB |
Output is correct |
79 |
Correct |
58 ms |
4344 KB |
Output is correct |
80 |
Correct |
57 ms |
4344 KB |
Output is correct |
81 |
Correct |
57 ms |
4344 KB |
Output is correct |
82 |
Correct |
60 ms |
4344 KB |
Output is correct |
83 |
Correct |
57 ms |
4344 KB |
Output is correct |
84 |
Correct |
57 ms |
4348 KB |
Output is correct |
85 |
Correct |
58 ms |
4348 KB |
Output is correct |
86 |
Correct |
57 ms |
4344 KB |
Output is correct |
87 |
Correct |
59 ms |
4344 KB |
Output is correct |
88 |
Correct |
59 ms |
4348 KB |
Output is correct |
89 |
Correct |
57 ms |
4344 KB |
Output is correct |
90 |
Correct |
60 ms |
4344 KB |
Output is correct |