#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 3e3 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
ll n, m;
str s[N];
int Right(int i, int j){
if(j + 2 >= m) return false;
return (s[i][j] == 'R') && (s[i][j + 1] == 'G') && (s[i][j + 2] == 'W');
}
int Down(int i, int j){
if(i + 2 >= n) return false;
return (s[i][j] == 'R') && (s[i + 1][j] == 'G') && (s[i + 2][j] == 'W');
}
vector<int> V[N + N];
int dp[N][4];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> s[i];
for(int i = 0; i < n + m - 1; i++) V[i].pb(0);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
V[i + j].pb(Right(i, j) * 2 + Down(i, j));
}
}
ll ans = 0;
int k;
for(int i = 0; i < n + m - 1; i++){
k = V[i].size();
for(int i = 0; i < k; i++) fill(dp[i], dp[i] + 4, -Inf);
dp[0][0] = 0;
for(int j = 1; j < k; j++){
for(int mk = 0; mk < 4; mk++){
dp[j][(mk << 1) & 3] = max(dp[j][(mk << 1) & 3], dp[j - 1][mk]);
}
if(V[i][j] & 1){
for(int mk = 0; mk < 4; mk++){
dp[j][(mk << 1 | 1 ) & 3] = max(dp[j][(mk << 1 | 1 ) & 3], dp[j - 1][mk] + 1);
}
}
if(V[i][j] & 2){
dp[j][0] = max(dp[j][0], dp[j - 1][0] + 1);
}
}
ans += *max_element(dp[k - 1], dp[k - 1] + 4);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
512 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
640 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
5 ms |
512 KB |
Output is correct |
31 |
Correct |
5 ms |
512 KB |
Output is correct |
32 |
Correct |
5 ms |
512 KB |
Output is correct |
33 |
Correct |
5 ms |
512 KB |
Output is correct |
34 |
Correct |
5 ms |
640 KB |
Output is correct |
35 |
Correct |
5 ms |
512 KB |
Output is correct |
36 |
Correct |
5 ms |
512 KB |
Output is correct |
37 |
Correct |
5 ms |
512 KB |
Output is correct |
38 |
Correct |
5 ms |
512 KB |
Output is correct |
39 |
Correct |
5 ms |
640 KB |
Output is correct |
40 |
Correct |
5 ms |
512 KB |
Output is correct |
41 |
Correct |
5 ms |
512 KB |
Output is correct |
42 |
Correct |
5 ms |
512 KB |
Output is correct |
43 |
Correct |
5 ms |
512 KB |
Output is correct |
44 |
Correct |
5 ms |
512 KB |
Output is correct |
45 |
Correct |
5 ms |
512 KB |
Output is correct |
46 |
Correct |
5 ms |
512 KB |
Output is correct |
47 |
Correct |
5 ms |
512 KB |
Output is correct |
48 |
Correct |
5 ms |
512 KB |
Output is correct |
49 |
Correct |
5 ms |
512 KB |
Output is correct |
50 |
Correct |
5 ms |
512 KB |
Output is correct |
51 |
Correct |
5 ms |
640 KB |
Output is correct |
52 |
Correct |
5 ms |
640 KB |
Output is correct |
53 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
512 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
512 KB |
Output is correct |
24 |
Correct |
5 ms |
512 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
640 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
5 ms |
512 KB |
Output is correct |
31 |
Correct |
5 ms |
512 KB |
Output is correct |
32 |
Correct |
5 ms |
512 KB |
Output is correct |
33 |
Correct |
5 ms |
512 KB |
Output is correct |
34 |
Correct |
5 ms |
640 KB |
Output is correct |
35 |
Correct |
5 ms |
512 KB |
Output is correct |
36 |
Correct |
5 ms |
512 KB |
Output is correct |
37 |
Correct |
5 ms |
512 KB |
Output is correct |
38 |
Correct |
5 ms |
512 KB |
Output is correct |
39 |
Correct |
5 ms |
640 KB |
Output is correct |
40 |
Correct |
5 ms |
512 KB |
Output is correct |
41 |
Correct |
5 ms |
512 KB |
Output is correct |
42 |
Correct |
5 ms |
512 KB |
Output is correct |
43 |
Correct |
5 ms |
512 KB |
Output is correct |
44 |
Correct |
5 ms |
512 KB |
Output is correct |
45 |
Correct |
5 ms |
512 KB |
Output is correct |
46 |
Correct |
5 ms |
512 KB |
Output is correct |
47 |
Correct |
5 ms |
512 KB |
Output is correct |
48 |
Correct |
5 ms |
512 KB |
Output is correct |
49 |
Correct |
5 ms |
512 KB |
Output is correct |
50 |
Correct |
5 ms |
512 KB |
Output is correct |
51 |
Correct |
5 ms |
640 KB |
Output is correct |
52 |
Correct |
5 ms |
640 KB |
Output is correct |
53 |
Correct |
5 ms |
512 KB |
Output is correct |
54 |
Correct |
5 ms |
640 KB |
Output is correct |
55 |
Correct |
5 ms |
640 KB |
Output is correct |
56 |
Correct |
6 ms |
768 KB |
Output is correct |
57 |
Correct |
6 ms |
768 KB |
Output is correct |
58 |
Correct |
32 ms |
7936 KB |
Output is correct |
59 |
Correct |
247 ms |
68472 KB |
Output is correct |
60 |
Correct |
250 ms |
68472 KB |
Output is correct |
61 |
Correct |
242 ms |
68472 KB |
Output is correct |
62 |
Correct |
5 ms |
640 KB |
Output is correct |
63 |
Correct |
235 ms |
66528 KB |
Output is correct |
64 |
Correct |
230 ms |
68600 KB |
Output is correct |
65 |
Correct |
230 ms |
68472 KB |
Output is correct |
66 |
Correct |
225 ms |
68600 KB |
Output is correct |
67 |
Correct |
212 ms |
68728 KB |
Output is correct |
68 |
Correct |
208 ms |
68472 KB |
Output is correct |
69 |
Correct |
210 ms |
68472 KB |
Output is correct |
70 |
Correct |
26 ms |
7936 KB |
Output is correct |
71 |
Correct |
28 ms |
7936 KB |
Output is correct |
72 |
Correct |
26 ms |
7936 KB |
Output is correct |
73 |
Correct |
27 ms |
7936 KB |
Output is correct |
74 |
Correct |
35 ms |
7936 KB |
Output is correct |
75 |
Correct |
26 ms |
7936 KB |
Output is correct |
76 |
Correct |
27 ms |
7936 KB |
Output is correct |
77 |
Correct |
27 ms |
7936 KB |
Output is correct |
78 |
Correct |
26 ms |
7936 KB |
Output is correct |
79 |
Correct |
26 ms |
7936 KB |
Output is correct |
80 |
Correct |
26 ms |
7936 KB |
Output is correct |
81 |
Correct |
26 ms |
7936 KB |
Output is correct |
82 |
Correct |
27 ms |
7936 KB |
Output is correct |
83 |
Correct |
27 ms |
7936 KB |
Output is correct |
84 |
Correct |
26 ms |
7936 KB |
Output is correct |
85 |
Correct |
26 ms |
7936 KB |
Output is correct |
86 |
Correct |
27 ms |
7936 KB |
Output is correct |
87 |
Correct |
26 ms |
7936 KB |
Output is correct |
88 |
Correct |
26 ms |
7936 KB |
Output is correct |
89 |
Correct |
26 ms |
7936 KB |
Output is correct |
90 |
Correct |
27 ms |
7936 KB |
Output is correct |