/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#define taskname "bai3"
#define all(x) x.begin(), x.end()
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
using namespace std;
using cd = complex<double>;
const int mxN = 3e3 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, m, a[mxN][mxN];
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
char c; cin >> c;
if(c == 'R') a[i][j] = 0;
else if(c == 'G') a[i][j] = 1;
else a[i][j] = 2;
//cout << a[i][j] << " ";
}
//cout << "\n";
}
int ans = 0;
for(int sum = 2; sum <= n + m; ++sum) {
int dp[mxN][2], cnt = 0;
memset(dp, 0, sizeof dp);
for(int i = 1; i <= n; ++i) {
int j = sum - i;
if(j > m || j < 1)
continue;
if(i < 3)
dp[i][0] = 0;
else {
int tmp = 0;
if(a[i][j] == 2 && a[i - 1][j] == 1 && a[i - 2][j] == 0)
tmp = 1;
dp[i][0] = max(dp[i - 1][0], dp[i - 3][1]) + tmp;
}
if(j < 3) {
dp[i][1] = dp[i - 1][1];
if(i > 3)
dp[i][1] = max(dp[i][1], dp[i - 3][0]);
}
else {
int tmp = 0;
if(a[i][j] == 2 && a[i][j - 1] == 1 && a[i][j - 2] == 0)
tmp = 1;
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + tmp;
}
cnt = max({cnt, dp[i][0], dp[i][1]});
}
ans += cnt;
}
cout << ans << "\n";
}
signed main() {
#ifdef CDuongg
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
352 KB |
Output is correct |
47 |
Correct |
0 ms |
352 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
0 ms |
352 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
352 KB |
Output is correct |
47 |
Correct |
0 ms |
352 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
0 ms |
352 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
2 ms |
340 KB |
Output is correct |
55 |
Correct |
14 ms |
12372 KB |
Output is correct |
56 |
Correct |
2 ms |
340 KB |
Output is correct |
57 |
Correct |
8 ms |
8404 KB |
Output is correct |
58 |
Correct |
37 ms |
8612 KB |
Output is correct |
59 |
Correct |
318 ms |
36540 KB |
Output is correct |
60 |
Correct |
326 ms |
36656 KB |
Output is correct |
61 |
Correct |
327 ms |
36788 KB |
Output is correct |
62 |
Correct |
2 ms |
340 KB |
Output is correct |
63 |
Correct |
310 ms |
36768 KB |
Output is correct |
64 |
Correct |
201 ms |
36812 KB |
Output is correct |
65 |
Correct |
203 ms |
36652 KB |
Output is correct |
66 |
Correct |
207 ms |
36584 KB |
Output is correct |
67 |
Correct |
193 ms |
36460 KB |
Output is correct |
68 |
Correct |
193 ms |
36356 KB |
Output is correct |
69 |
Correct |
204 ms |
35888 KB |
Output is correct |
70 |
Correct |
22 ms |
8148 KB |
Output is correct |
71 |
Correct |
21 ms |
8280 KB |
Output is correct |
72 |
Correct |
22 ms |
8192 KB |
Output is correct |
73 |
Correct |
22 ms |
8188 KB |
Output is correct |
74 |
Correct |
22 ms |
8276 KB |
Output is correct |
75 |
Correct |
22 ms |
8272 KB |
Output is correct |
76 |
Correct |
22 ms |
8148 KB |
Output is correct |
77 |
Correct |
22 ms |
8276 KB |
Output is correct |
78 |
Correct |
23 ms |
8212 KB |
Output is correct |
79 |
Correct |
22 ms |
8160 KB |
Output is correct |
80 |
Correct |
22 ms |
8260 KB |
Output is correct |
81 |
Correct |
22 ms |
8276 KB |
Output is correct |
82 |
Correct |
22 ms |
8256 KB |
Output is correct |
83 |
Correct |
22 ms |
8276 KB |
Output is correct |
84 |
Correct |
24 ms |
8268 KB |
Output is correct |
85 |
Correct |
23 ms |
8204 KB |
Output is correct |
86 |
Correct |
23 ms |
8280 KB |
Output is correct |
87 |
Correct |
22 ms |
8276 KB |
Output is correct |
88 |
Correct |
22 ms |
8236 KB |
Output is correct |
89 |
Correct |
22 ms |
8404 KB |
Output is correct |
90 |
Correct |
22 ms |
8276 KB |
Output is correct |