#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
const int mxn = 3002, k = 2, w = 3;
const char c[w] = {'R', 'G', 'W'};
const int dx[k << 1] = {-1, 0, 1, 0};
const int dy[k << 1] = {0, -1, 0, 1};
int n, m;
int a[mxn][mxn], b[mxn][mxn];
int dp[mxn][mxn][2];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++){
char x;
cin >> x;
a[i][j] = find(c, c + w, x) - c;
}
int ret = 0;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++){
if(!~-a[i][j]){
for(int p = 0; p < k; p++){
b[i][j] ^= 1 << p;
for(int l = 0; l < 2; l++){
int x = i + dx[(p + l * k) % (2 * k)], y = j + dy[(p + l * k) % (2 * k)];
if(x < 1 || y < 1 || x > n || y > m || a[x][y] != 2 * l){
b[i][j] ^= 1 << p;
break;
}
}
}
}
for(int p = 0; p < 2; p++)
for(int l = 0; l < 2; l++){
int x = ((b[i][j] >> p) & 1), y = ((b[i - 1][j + 1] >> l) & 1);
if(p == l || !x || !y){
dp[i][j][p] = max(dp[i][j][p], dp[i - 1][j + 1][l] + x);
}
}
if(i == n || !~-j) ret += max(dp[i][j][0], dp[i][j][1]);
}
cout << ret << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
512 KB |
Output is correct |
21 |
Correct |
0 ms |
512 KB |
Output is correct |
22 |
Correct |
0 ms |
512 KB |
Output is correct |
23 |
Correct |
0 ms |
512 KB |
Output is correct |
24 |
Correct |
0 ms |
512 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
0 ms |
512 KB |
Output is correct |
37 |
Correct |
1 ms |
512 KB |
Output is correct |
38 |
Correct |
0 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
1 ms |
512 KB |
Output is correct |
41 |
Correct |
1 ms |
512 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
1 ms |
512 KB |
Output is correct |
45 |
Correct |
0 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
1 ms |
512 KB |
Output is correct |
50 |
Correct |
1 ms |
512 KB |
Output is correct |
51 |
Correct |
1 ms |
512 KB |
Output is correct |
52 |
Correct |
0 ms |
512 KB |
Output is correct |
53 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
512 KB |
Output is correct |
21 |
Correct |
0 ms |
512 KB |
Output is correct |
22 |
Correct |
0 ms |
512 KB |
Output is correct |
23 |
Correct |
0 ms |
512 KB |
Output is correct |
24 |
Correct |
0 ms |
512 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
0 ms |
512 KB |
Output is correct |
37 |
Correct |
1 ms |
512 KB |
Output is correct |
38 |
Correct |
0 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
1 ms |
512 KB |
Output is correct |
41 |
Correct |
1 ms |
512 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
1 ms |
512 KB |
Output is correct |
45 |
Correct |
0 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
1 ms |
512 KB |
Output is correct |
50 |
Correct |
1 ms |
512 KB |
Output is correct |
51 |
Correct |
1 ms |
512 KB |
Output is correct |
52 |
Correct |
0 ms |
512 KB |
Output is correct |
53 |
Correct |
1 ms |
512 KB |
Output is correct |
54 |
Correct |
1 ms |
384 KB |
Output is correct |
55 |
Correct |
18 ms |
28672 KB |
Output is correct |
56 |
Correct |
1 ms |
640 KB |
Output is correct |
57 |
Correct |
15 ms |
24576 KB |
Output is correct |
58 |
Correct |
65 ms |
28024 KB |
Output is correct |
59 |
Correct |
446 ms |
141432 KB |
Output is correct |
60 |
Correct |
448 ms |
143608 KB |
Output is correct |
61 |
Correct |
448 ms |
143532 KB |
Output is correct |
62 |
Correct |
1 ms |
512 KB |
Output is correct |
63 |
Correct |
432 ms |
143608 KB |
Output is correct |
64 |
Correct |
298 ms |
143608 KB |
Output is correct |
65 |
Correct |
308 ms |
143608 KB |
Output is correct |
66 |
Correct |
298 ms |
143480 KB |
Output is correct |
67 |
Correct |
294 ms |
127388 KB |
Output is correct |
68 |
Correct |
297 ms |
140664 KB |
Output is correct |
69 |
Correct |
312 ms |
143608 KB |
Output is correct |
70 |
Correct |
43 ms |
29048 KB |
Output is correct |
71 |
Correct |
42 ms |
29048 KB |
Output is correct |
72 |
Correct |
49 ms |
29048 KB |
Output is correct |
73 |
Correct |
41 ms |
29036 KB |
Output is correct |
74 |
Correct |
42 ms |
29048 KB |
Output is correct |
75 |
Correct |
40 ms |
29056 KB |
Output is correct |
76 |
Correct |
45 ms |
29048 KB |
Output is correct |
77 |
Correct |
41 ms |
29048 KB |
Output is correct |
78 |
Correct |
39 ms |
29048 KB |
Output is correct |
79 |
Correct |
39 ms |
29048 KB |
Output is correct |
80 |
Correct |
39 ms |
29048 KB |
Output is correct |
81 |
Correct |
40 ms |
29072 KB |
Output is correct |
82 |
Correct |
42 ms |
29048 KB |
Output is correct |
83 |
Correct |
40 ms |
29048 KB |
Output is correct |
84 |
Correct |
39 ms |
29048 KB |
Output is correct |
85 |
Correct |
39 ms |
29048 KB |
Output is correct |
86 |
Correct |
39 ms |
29048 KB |
Output is correct |
87 |
Correct |
39 ms |
29048 KB |
Output is correct |
88 |
Correct |
41 ms |
29048 KB |
Output is correct |
89 |
Correct |
40 ms |
29048 KB |
Output is correct |
90 |
Correct |
39 ms |
29048 KB |
Output is correct |