// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e3+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
vector<string> a(N, string(N, '0'));
array<array<int,2>, 2> dp, dpn;
int ans = 0;
inline void solve() {
cin>>n>>m;
for(int i = 1; i<=n; i++) {
cin>>a[i];
a[i] = '0' + a[i] + "000";
}
for(int t = 2; t<=n + m; t++) {
dp = {0,0,0,0};
for(int i = max(1, t - m); i <= n; i++) {
int j = t - i;
if(j < 1) break;
if(a[i][j] != 'R') {
dp[0][0] = max(dp[0][0], dp[0][1]);
dp[0][1] = max(dp[1][0], dp[1][1]);
dp[1][0] = dp[1][1] = 0;
continue;
}
for(int f1 = 0; f1<2; f1++) {
for(int f2 = 0; f2<2; f2++) {
dpn[f1][f2] = 0;
if(f1) {
if(a[i + 1][j] == 'G' && a[i + 2][j] == 'W') {
dpn[f1][f2] = max(dp[f2][0], dp[f2][1]) + 1;
}
}
else {
if(!f2 && a[i][j + 1] == 'G' && a[i][j + 2] == 'W') {
dpn[f1][f2] = dp[0][0] + 1;
}
dpn[f1][f2] = max(dpn[f1][f2], max(dp[f2][0], dp[f2][1]));
}
}
}
swap(dpn, dp);
}
ans += max(max(dp[0][0], dp[0][1]) , max(dp[1][0], dp[1][1]) );
}
cout << ans << "\n";
}
signed main() {
//fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9304 KB |
Output is correct |
2 |
Correct |
6 ms |
9304 KB |
Output is correct |
3 |
Correct |
6 ms |
9412 KB |
Output is correct |
4 |
Correct |
6 ms |
9308 KB |
Output is correct |
5 |
Correct |
7 ms |
9388 KB |
Output is correct |
6 |
Correct |
6 ms |
9244 KB |
Output is correct |
7 |
Correct |
6 ms |
9308 KB |
Output is correct |
8 |
Correct |
6 ms |
9308 KB |
Output is correct |
9 |
Correct |
7 ms |
9308 KB |
Output is correct |
10 |
Correct |
6 ms |
9304 KB |
Output is correct |
11 |
Correct |
6 ms |
9308 KB |
Output is correct |
12 |
Correct |
6 ms |
9308 KB |
Output is correct |
13 |
Correct |
6 ms |
9308 KB |
Output is correct |
14 |
Correct |
6 ms |
9308 KB |
Output is correct |
15 |
Correct |
7 ms |
9304 KB |
Output is correct |
16 |
Correct |
6 ms |
9304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9304 KB |
Output is correct |
2 |
Correct |
6 ms |
9304 KB |
Output is correct |
3 |
Correct |
6 ms |
9412 KB |
Output is correct |
4 |
Correct |
6 ms |
9308 KB |
Output is correct |
5 |
Correct |
7 ms |
9388 KB |
Output is correct |
6 |
Correct |
6 ms |
9244 KB |
Output is correct |
7 |
Correct |
6 ms |
9308 KB |
Output is correct |
8 |
Correct |
6 ms |
9308 KB |
Output is correct |
9 |
Correct |
7 ms |
9308 KB |
Output is correct |
10 |
Correct |
6 ms |
9304 KB |
Output is correct |
11 |
Correct |
6 ms |
9308 KB |
Output is correct |
12 |
Correct |
6 ms |
9308 KB |
Output is correct |
13 |
Correct |
6 ms |
9308 KB |
Output is correct |
14 |
Correct |
6 ms |
9308 KB |
Output is correct |
15 |
Correct |
7 ms |
9304 KB |
Output is correct |
16 |
Correct |
6 ms |
9304 KB |
Output is correct |
17 |
Correct |
6 ms |
9308 KB |
Output is correct |
18 |
Correct |
6 ms |
9308 KB |
Output is correct |
19 |
Correct |
6 ms |
9408 KB |
Output is correct |
20 |
Correct |
6 ms |
9276 KB |
Output is correct |
21 |
Correct |
6 ms |
9560 KB |
Output is correct |
22 |
Correct |
6 ms |
9304 KB |
Output is correct |
23 |
Correct |
6 ms |
9308 KB |
Output is correct |
24 |
Correct |
7 ms |
9308 KB |
Output is correct |
25 |
Correct |
6 ms |
9420 KB |
Output is correct |
26 |
Correct |
6 ms |
9308 KB |
Output is correct |
27 |
Correct |
7 ms |
9308 KB |
Output is correct |
28 |
Correct |
6 ms |
9308 KB |
Output is correct |
29 |
Correct |
6 ms |
9308 KB |
Output is correct |
30 |
Correct |
6 ms |
9364 KB |
Output is correct |
31 |
Correct |
6 ms |
9560 KB |
Output is correct |
32 |
Correct |
6 ms |
9308 KB |
Output is correct |
33 |
Correct |
7 ms |
9556 KB |
Output is correct |
34 |
Correct |
8 ms |
9308 KB |
Output is correct |
35 |
Correct |
6 ms |
9308 KB |
Output is correct |
36 |
Correct |
6 ms |
9308 KB |
Output is correct |
37 |
Correct |
6 ms |
9308 KB |
Output is correct |
38 |
Correct |
6 ms |
9308 KB |
Output is correct |
39 |
Correct |
6 ms |
9416 KB |
Output is correct |
40 |
Correct |
6 ms |
9308 KB |
Output is correct |
41 |
Correct |
6 ms |
9308 KB |
Output is correct |
42 |
Correct |
6 ms |
9396 KB |
Output is correct |
43 |
Correct |
7 ms |
9308 KB |
Output is correct |
44 |
Correct |
6 ms |
9308 KB |
Output is correct |
45 |
Correct |
6 ms |
9268 KB |
Output is correct |
46 |
Correct |
6 ms |
9308 KB |
Output is correct |
47 |
Correct |
7 ms |
9308 KB |
Output is correct |
48 |
Correct |
6 ms |
9308 KB |
Output is correct |
49 |
Correct |
7 ms |
9308 KB |
Output is correct |
50 |
Correct |
6 ms |
9428 KB |
Output is correct |
51 |
Correct |
6 ms |
9308 KB |
Output is correct |
52 |
Correct |
6 ms |
9308 KB |
Output is correct |
53 |
Correct |
6 ms |
9308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9304 KB |
Output is correct |
2 |
Correct |
6 ms |
9304 KB |
Output is correct |
3 |
Correct |
6 ms |
9412 KB |
Output is correct |
4 |
Correct |
6 ms |
9308 KB |
Output is correct |
5 |
Correct |
7 ms |
9388 KB |
Output is correct |
6 |
Correct |
6 ms |
9244 KB |
Output is correct |
7 |
Correct |
6 ms |
9308 KB |
Output is correct |
8 |
Correct |
6 ms |
9308 KB |
Output is correct |
9 |
Correct |
7 ms |
9308 KB |
Output is correct |
10 |
Correct |
6 ms |
9304 KB |
Output is correct |
11 |
Correct |
6 ms |
9308 KB |
Output is correct |
12 |
Correct |
6 ms |
9308 KB |
Output is correct |
13 |
Correct |
6 ms |
9308 KB |
Output is correct |
14 |
Correct |
6 ms |
9308 KB |
Output is correct |
15 |
Correct |
7 ms |
9304 KB |
Output is correct |
16 |
Correct |
6 ms |
9304 KB |
Output is correct |
17 |
Correct |
6 ms |
9308 KB |
Output is correct |
18 |
Correct |
6 ms |
9308 KB |
Output is correct |
19 |
Correct |
6 ms |
9408 KB |
Output is correct |
20 |
Correct |
6 ms |
9276 KB |
Output is correct |
21 |
Correct |
6 ms |
9560 KB |
Output is correct |
22 |
Correct |
6 ms |
9304 KB |
Output is correct |
23 |
Correct |
6 ms |
9308 KB |
Output is correct |
24 |
Correct |
7 ms |
9308 KB |
Output is correct |
25 |
Correct |
6 ms |
9420 KB |
Output is correct |
26 |
Correct |
6 ms |
9308 KB |
Output is correct |
27 |
Correct |
7 ms |
9308 KB |
Output is correct |
28 |
Correct |
6 ms |
9308 KB |
Output is correct |
29 |
Correct |
6 ms |
9308 KB |
Output is correct |
30 |
Correct |
6 ms |
9364 KB |
Output is correct |
31 |
Correct |
6 ms |
9560 KB |
Output is correct |
32 |
Correct |
6 ms |
9308 KB |
Output is correct |
33 |
Correct |
7 ms |
9556 KB |
Output is correct |
34 |
Correct |
8 ms |
9308 KB |
Output is correct |
35 |
Correct |
6 ms |
9308 KB |
Output is correct |
36 |
Correct |
6 ms |
9308 KB |
Output is correct |
37 |
Correct |
6 ms |
9308 KB |
Output is correct |
38 |
Correct |
6 ms |
9308 KB |
Output is correct |
39 |
Correct |
6 ms |
9416 KB |
Output is correct |
40 |
Correct |
6 ms |
9308 KB |
Output is correct |
41 |
Correct |
6 ms |
9308 KB |
Output is correct |
42 |
Correct |
6 ms |
9396 KB |
Output is correct |
43 |
Correct |
7 ms |
9308 KB |
Output is correct |
44 |
Correct |
6 ms |
9308 KB |
Output is correct |
45 |
Correct |
6 ms |
9268 KB |
Output is correct |
46 |
Correct |
6 ms |
9308 KB |
Output is correct |
47 |
Correct |
7 ms |
9308 KB |
Output is correct |
48 |
Correct |
6 ms |
9308 KB |
Output is correct |
49 |
Correct |
7 ms |
9308 KB |
Output is correct |
50 |
Correct |
6 ms |
9428 KB |
Output is correct |
51 |
Correct |
6 ms |
9308 KB |
Output is correct |
52 |
Correct |
6 ms |
9308 KB |
Output is correct |
53 |
Correct |
6 ms |
9308 KB |
Output is correct |
54 |
Correct |
6 ms |
9308 KB |
Output is correct |
55 |
Correct |
6 ms |
9308 KB |
Output is correct |
56 |
Correct |
7 ms |
9308 KB |
Output is correct |
57 |
Correct |
7 ms |
9308 KB |
Output is correct |
58 |
Correct |
30 ms |
10296 KB |
Output is correct |
59 |
Correct |
249 ms |
26980 KB |
Output is correct |
60 |
Correct |
248 ms |
26964 KB |
Output is correct |
61 |
Correct |
244 ms |
26960 KB |
Output is correct |
62 |
Correct |
7 ms |
9564 KB |
Output is correct |
63 |
Correct |
230 ms |
25940 KB |
Output is correct |
64 |
Correct |
195 ms |
26960 KB |
Output is correct |
65 |
Correct |
199 ms |
27064 KB |
Output is correct |
66 |
Correct |
203 ms |
26984 KB |
Output is correct |
67 |
Correct |
240 ms |
26964 KB |
Output is correct |
68 |
Correct |
197 ms |
26796 KB |
Output is correct |
69 |
Correct |
198 ms |
27236 KB |
Output is correct |
70 |
Correct |
24 ms |
10400 KB |
Output is correct |
71 |
Correct |
24 ms |
10332 KB |
Output is correct |
72 |
Correct |
24 ms |
10332 KB |
Output is correct |
73 |
Correct |
25 ms |
10332 KB |
Output is correct |
74 |
Correct |
24 ms |
10332 KB |
Output is correct |
75 |
Correct |
24 ms |
10208 KB |
Output is correct |
76 |
Correct |
25 ms |
10388 KB |
Output is correct |
77 |
Correct |
24 ms |
10328 KB |
Output is correct |
78 |
Correct |
25 ms |
10332 KB |
Output is correct |
79 |
Correct |
25 ms |
10264 KB |
Output is correct |
80 |
Correct |
30 ms |
10324 KB |
Output is correct |
81 |
Correct |
25 ms |
10332 KB |
Output is correct |
82 |
Correct |
25 ms |
10324 KB |
Output is correct |
83 |
Correct |
24 ms |
10332 KB |
Output is correct |
84 |
Correct |
24 ms |
10332 KB |
Output is correct |
85 |
Correct |
23 ms |
10332 KB |
Output is correct |
86 |
Correct |
25 ms |
10332 KB |
Output is correct |
87 |
Correct |
24 ms |
10176 KB |
Output is correct |
88 |
Correct |
25 ms |
10320 KB |
Output is correct |
89 |
Correct |
22 ms |
10476 KB |
Output is correct |
90 |
Correct |
24 ms |
10332 KB |
Output is correct |