/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
// lethal option
#include<bits/stdc++.h>
using namespace std;
#define all(flg) flg.begin(), flg.end()
#define int long long
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define eb emplace_back
#define ii pair<int, int>
#define vi vector<int>
#define PI 3.141592653589793238462643383279502884
#define ll long long
#define ld long double
#define for1(i, ff, gg) for(int i = ff; i <= gg; ++i)
#define for2(i, ff, gg) for(int i = ff; i >= gg; --i)
const ll mod = 1e9 + 7;
const int maxN = 3005;
const ll oo = 1e18 + 7;
int n, a[maxN];
int x, y, z, k, m;
int dp[maxN][maxN][2];
char c[maxN][maxN];
signed main(){
// freopen(".inp", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
memset(dp, 0, sizeof(dp));
memset(c, 0, sizeof(c));
cin >> n >> m;
for1(i, 1, n) for1(j, 1, m) cin >> c[i][j];
for2(i, n, 1) for2(j, m, 1){
string s;
s.clear();
for1(g, j, j + 2) s.pb(c[i][g]);
if(s == "RGW"){
dp[i][j][0] = max(dp[i + 1][j - 1][0], dp[i + 1][j - 1][1]) + 1;
}
s.clear();
for1(g, i, i + 2) s.pb(c[g][j]);
if(s == "RGW"){
dp[i][j][1] = max((j >= 3 ? dp[i + 3][j - 3][0] : 0), dp[i + 1][j - 1][1]) + 1;
}
for1(g, 0, 1){
dp[i][j][g] = max(dp[i][j][g], dp[i + 1][j - 1][g]);
}
}
// cout << dp[2][1][0] << " " << dp[2][1][1] << endl;
int ans = 0;
for1(i, 1, n){
for1(j, 1, m) if(j == m || i == 1) ans += max(dp[i][j][0], dp[i][j][1]);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
150520 KB |
Output is correct |
2 |
Correct |
56 ms |
150412 KB |
Output is correct |
3 |
Correct |
55 ms |
150476 KB |
Output is correct |
4 |
Correct |
65 ms |
150508 KB |
Output is correct |
5 |
Correct |
66 ms |
150420 KB |
Output is correct |
6 |
Correct |
54 ms |
150572 KB |
Output is correct |
7 |
Correct |
55 ms |
150604 KB |
Output is correct |
8 |
Correct |
54 ms |
150476 KB |
Output is correct |
9 |
Correct |
54 ms |
150480 KB |
Output is correct |
10 |
Correct |
56 ms |
150444 KB |
Output is correct |
11 |
Correct |
62 ms |
150452 KB |
Output is correct |
12 |
Correct |
58 ms |
150448 KB |
Output is correct |
13 |
Correct |
60 ms |
150476 KB |
Output is correct |
14 |
Correct |
60 ms |
150504 KB |
Output is correct |
15 |
Correct |
60 ms |
150408 KB |
Output is correct |
16 |
Correct |
61 ms |
150488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
150520 KB |
Output is correct |
2 |
Correct |
56 ms |
150412 KB |
Output is correct |
3 |
Correct |
55 ms |
150476 KB |
Output is correct |
4 |
Correct |
65 ms |
150508 KB |
Output is correct |
5 |
Correct |
66 ms |
150420 KB |
Output is correct |
6 |
Correct |
54 ms |
150572 KB |
Output is correct |
7 |
Correct |
55 ms |
150604 KB |
Output is correct |
8 |
Correct |
54 ms |
150476 KB |
Output is correct |
9 |
Correct |
54 ms |
150480 KB |
Output is correct |
10 |
Correct |
56 ms |
150444 KB |
Output is correct |
11 |
Correct |
62 ms |
150452 KB |
Output is correct |
12 |
Correct |
58 ms |
150448 KB |
Output is correct |
13 |
Correct |
60 ms |
150476 KB |
Output is correct |
14 |
Correct |
60 ms |
150504 KB |
Output is correct |
15 |
Correct |
60 ms |
150408 KB |
Output is correct |
16 |
Correct |
61 ms |
150488 KB |
Output is correct |
17 |
Correct |
53 ms |
150500 KB |
Output is correct |
18 |
Correct |
53 ms |
150440 KB |
Output is correct |
19 |
Correct |
57 ms |
150412 KB |
Output is correct |
20 |
Correct |
63 ms |
150440 KB |
Output is correct |
21 |
Correct |
55 ms |
150460 KB |
Output is correct |
22 |
Correct |
60 ms |
150428 KB |
Output is correct |
23 |
Correct |
54 ms |
150468 KB |
Output is correct |
24 |
Correct |
55 ms |
150504 KB |
Output is correct |
25 |
Correct |
64 ms |
150476 KB |
Output is correct |
26 |
Correct |
57 ms |
150476 KB |
Output is correct |
27 |
Correct |
55 ms |
150448 KB |
Output is correct |
28 |
Correct |
59 ms |
150420 KB |
Output is correct |
29 |
Correct |
57 ms |
150432 KB |
Output is correct |
30 |
Correct |
58 ms |
150444 KB |
Output is correct |
31 |
Correct |
55 ms |
150472 KB |
Output is correct |
32 |
Correct |
55 ms |
150428 KB |
Output is correct |
33 |
Correct |
54 ms |
150508 KB |
Output is correct |
34 |
Correct |
64 ms |
150400 KB |
Output is correct |
35 |
Correct |
64 ms |
150408 KB |
Output is correct |
36 |
Correct |
55 ms |
150408 KB |
Output is correct |
37 |
Correct |
54 ms |
150472 KB |
Output is correct |
38 |
Correct |
61 ms |
150396 KB |
Output is correct |
39 |
Correct |
55 ms |
150448 KB |
Output is correct |
40 |
Correct |
52 ms |
150472 KB |
Output is correct |
41 |
Correct |
64 ms |
150408 KB |
Output is correct |
42 |
Correct |
60 ms |
150448 KB |
Output is correct |
43 |
Correct |
58 ms |
150472 KB |
Output is correct |
44 |
Correct |
55 ms |
150476 KB |
Output is correct |
45 |
Correct |
54 ms |
150484 KB |
Output is correct |
46 |
Correct |
54 ms |
150440 KB |
Output is correct |
47 |
Correct |
55 ms |
150508 KB |
Output is correct |
48 |
Correct |
60 ms |
150420 KB |
Output is correct |
49 |
Correct |
55 ms |
150424 KB |
Output is correct |
50 |
Correct |
54 ms |
150496 KB |
Output is correct |
51 |
Correct |
54 ms |
150504 KB |
Output is correct |
52 |
Correct |
64 ms |
150460 KB |
Output is correct |
53 |
Correct |
59 ms |
150392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
150520 KB |
Output is correct |
2 |
Correct |
56 ms |
150412 KB |
Output is correct |
3 |
Correct |
55 ms |
150476 KB |
Output is correct |
4 |
Correct |
65 ms |
150508 KB |
Output is correct |
5 |
Correct |
66 ms |
150420 KB |
Output is correct |
6 |
Correct |
54 ms |
150572 KB |
Output is correct |
7 |
Correct |
55 ms |
150604 KB |
Output is correct |
8 |
Correct |
54 ms |
150476 KB |
Output is correct |
9 |
Correct |
54 ms |
150480 KB |
Output is correct |
10 |
Correct |
56 ms |
150444 KB |
Output is correct |
11 |
Correct |
62 ms |
150452 KB |
Output is correct |
12 |
Correct |
58 ms |
150448 KB |
Output is correct |
13 |
Correct |
60 ms |
150476 KB |
Output is correct |
14 |
Correct |
60 ms |
150504 KB |
Output is correct |
15 |
Correct |
60 ms |
150408 KB |
Output is correct |
16 |
Correct |
61 ms |
150488 KB |
Output is correct |
17 |
Correct |
53 ms |
150500 KB |
Output is correct |
18 |
Correct |
53 ms |
150440 KB |
Output is correct |
19 |
Correct |
57 ms |
150412 KB |
Output is correct |
20 |
Correct |
63 ms |
150440 KB |
Output is correct |
21 |
Correct |
55 ms |
150460 KB |
Output is correct |
22 |
Correct |
60 ms |
150428 KB |
Output is correct |
23 |
Correct |
54 ms |
150468 KB |
Output is correct |
24 |
Correct |
55 ms |
150504 KB |
Output is correct |
25 |
Correct |
64 ms |
150476 KB |
Output is correct |
26 |
Correct |
57 ms |
150476 KB |
Output is correct |
27 |
Correct |
55 ms |
150448 KB |
Output is correct |
28 |
Correct |
59 ms |
150420 KB |
Output is correct |
29 |
Correct |
57 ms |
150432 KB |
Output is correct |
30 |
Correct |
58 ms |
150444 KB |
Output is correct |
31 |
Correct |
55 ms |
150472 KB |
Output is correct |
32 |
Correct |
55 ms |
150428 KB |
Output is correct |
33 |
Correct |
54 ms |
150508 KB |
Output is correct |
34 |
Correct |
64 ms |
150400 KB |
Output is correct |
35 |
Correct |
64 ms |
150408 KB |
Output is correct |
36 |
Correct |
55 ms |
150408 KB |
Output is correct |
37 |
Correct |
54 ms |
150472 KB |
Output is correct |
38 |
Correct |
61 ms |
150396 KB |
Output is correct |
39 |
Correct |
55 ms |
150448 KB |
Output is correct |
40 |
Correct |
52 ms |
150472 KB |
Output is correct |
41 |
Correct |
64 ms |
150408 KB |
Output is correct |
42 |
Correct |
60 ms |
150448 KB |
Output is correct |
43 |
Correct |
58 ms |
150472 KB |
Output is correct |
44 |
Correct |
55 ms |
150476 KB |
Output is correct |
45 |
Correct |
54 ms |
150484 KB |
Output is correct |
46 |
Correct |
54 ms |
150440 KB |
Output is correct |
47 |
Correct |
55 ms |
150508 KB |
Output is correct |
48 |
Correct |
60 ms |
150420 KB |
Output is correct |
49 |
Correct |
55 ms |
150424 KB |
Output is correct |
50 |
Correct |
54 ms |
150496 KB |
Output is correct |
51 |
Correct |
54 ms |
150504 KB |
Output is correct |
52 |
Correct |
64 ms |
150460 KB |
Output is correct |
53 |
Correct |
59 ms |
150392 KB |
Output is correct |
54 |
Correct |
61 ms |
150544 KB |
Output is correct |
55 |
Correct |
56 ms |
150412 KB |
Output is correct |
56 |
Correct |
59 ms |
150476 KB |
Output is correct |
57 |
Correct |
56 ms |
150476 KB |
Output is correct |
58 |
Correct |
116 ms |
150532 KB |
Output is correct |
59 |
Correct |
571 ms |
150512 KB |
Output is correct |
60 |
Correct |
569 ms |
150512 KB |
Output is correct |
61 |
Correct |
583 ms |
150508 KB |
Output is correct |
62 |
Correct |
60 ms |
150484 KB |
Output is correct |
63 |
Correct |
554 ms |
150508 KB |
Output is correct |
64 |
Correct |
637 ms |
150512 KB |
Output is correct |
65 |
Correct |
638 ms |
150516 KB |
Output is correct |
66 |
Correct |
623 ms |
150508 KB |
Output is correct |
67 |
Correct |
621 ms |
150512 KB |
Output is correct |
68 |
Correct |
572 ms |
150512 KB |
Output is correct |
69 |
Correct |
629 ms |
150512 KB |
Output is correct |
70 |
Correct |
116 ms |
150416 KB |
Output is correct |
71 |
Correct |
118 ms |
150476 KB |
Output is correct |
72 |
Correct |
122 ms |
150476 KB |
Output is correct |
73 |
Correct |
131 ms |
150512 KB |
Output is correct |
74 |
Correct |
124 ms |
150424 KB |
Output is correct |
75 |
Correct |
125 ms |
150508 KB |
Output is correct |
76 |
Correct |
120 ms |
150512 KB |
Output is correct |
77 |
Correct |
126 ms |
150512 KB |
Output is correct |
78 |
Correct |
122 ms |
150512 KB |
Output is correct |
79 |
Correct |
116 ms |
150444 KB |
Output is correct |
80 |
Correct |
118 ms |
150476 KB |
Output is correct |
81 |
Correct |
131 ms |
150512 KB |
Output is correct |
82 |
Correct |
131 ms |
150512 KB |
Output is correct |
83 |
Correct |
124 ms |
150508 KB |
Output is correct |
84 |
Correct |
119 ms |
150412 KB |
Output is correct |
85 |
Correct |
119 ms |
150512 KB |
Output is correct |
86 |
Correct |
130 ms |
150420 KB |
Output is correct |
87 |
Correct |
119 ms |
150508 KB |
Output is correct |
88 |
Correct |
118 ms |
150492 KB |
Output is correct |
89 |
Correct |
118 ms |
150428 KB |
Output is correct |
90 |
Correct |
129 ms |
150516 KB |
Output is correct |