#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>
using namespace std;
const int N = 3001;
int a[N][N];
int read() {
char c;
cin >> c;
if (c == 'R') return 0;
if (c == 'G') return 1;
if (c == 'W') return 2;
assert(false);
return -1;
}
int n, m;
int ok(int i, int j, int dir) {
if (dir == 0) {
if (i == 0 || i + 1 == n) return 0;
return a[i - 1][j] == 0 && a[i][j] == 1 && a[i + 1][j] == 2;
} else {
if (j == 0 || j + 1 == m) return 0;
return a[i][j - 1] == 0 && a[i][j] == 1 && a[i][j + 1] == 2;
}
}
int dp[3];
int ndp[3];
//0 - none
//1 - up
//2 - left
void rec(int cu, int cd) {
ndp[0] = max({dp[0], dp[1], dp[2]});
ndp[1] = max({dp[0], dp[1]}) + cu;
ndp[2] = max({dp[0], dp[2]}) + cd;
for (int i = 0; i < 3; i++) {
dp[i] = ndp[i];
ndp[i] = 0;
}
}
void init() {
fill(dp, dp + 3, 0);
fill(ndp, ndp + 3, 0);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = read();
}
}
int ans = 0;
for (int sm = 0; sm <= n + m; sm++) {
init();
for (int i = 0; i < n; i++) {
int j = sm - i;
if (j < 0 || j >= m) continue;
rec(ok(i, j, 0), ok(i, j, 1));
}
ans += max({dp[0], dp[1], dp[2]});
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 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 |
5 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 |
380 KB |
Output is correct |
16 |
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 |
380 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 |
5 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 |
380 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 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 |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 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 |
248 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 |
4 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 |
380 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 |
4 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 |
380 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 |
5 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 |
380 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 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 |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 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 |
248 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 |
4 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 |
380 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 |
4 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 |
21 ms |
12408 KB |
Output is correct |
56 |
Correct |
5 ms |
376 KB |
Output is correct |
57 |
Correct |
14 ms |
8440 KB |
Output is correct |
58 |
Correct |
66 ms |
9336 KB |
Output is correct |
59 |
Correct |
524 ms |
44536 KB |
Output is correct |
60 |
Correct |
520 ms |
44464 KB |
Output is correct |
61 |
Correct |
539 ms |
44424 KB |
Output is correct |
62 |
Correct |
5 ms |
376 KB |
Output is correct |
63 |
Correct |
500 ms |
44024 KB |
Output is correct |
64 |
Correct |
338 ms |
44536 KB |
Output is correct |
65 |
Correct |
329 ms |
44408 KB |
Output is correct |
66 |
Correct |
333 ms |
44428 KB |
Output is correct |
67 |
Correct |
327 ms |
44324 KB |
Output is correct |
68 |
Correct |
316 ms |
44408 KB |
Output is correct |
69 |
Correct |
330 ms |
44408 KB |
Output is correct |
70 |
Correct |
37 ms |
9208 KB |
Output is correct |
71 |
Correct |
43 ms |
9184 KB |
Output is correct |
72 |
Correct |
37 ms |
9208 KB |
Output is correct |
73 |
Correct |
40 ms |
9208 KB |
Output is correct |
74 |
Correct |
42 ms |
9328 KB |
Output is correct |
75 |
Correct |
38 ms |
9208 KB |
Output is correct |
76 |
Correct |
38 ms |
9208 KB |
Output is correct |
77 |
Correct |
45 ms |
9316 KB |
Output is correct |
78 |
Correct |
41 ms |
9208 KB |
Output is correct |
79 |
Correct |
37 ms |
9240 KB |
Output is correct |
80 |
Correct |
38 ms |
9208 KB |
Output is correct |
81 |
Correct |
38 ms |
9208 KB |
Output is correct |
82 |
Correct |
37 ms |
9208 KB |
Output is correct |
83 |
Correct |
37 ms |
9208 KB |
Output is correct |
84 |
Correct |
40 ms |
9208 KB |
Output is correct |
85 |
Correct |
38 ms |
9208 KB |
Output is correct |
86 |
Correct |
38 ms |
9208 KB |
Output is correct |
87 |
Correct |
31 ms |
9336 KB |
Output is correct |
88 |
Correct |
37 ms |
9208 KB |
Output is correct |
89 |
Correct |
37 ms |
9208 KB |
Output is correct |
90 |
Correct |
37 ms |
9208 KB |
Output is correct |