// In the name of Allah
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define debug(x) cerr << #x << ": " << x << endl;
#define kill(x) cout << x << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
int n, m;
const int maxn = 3e3 + 4;
int a[maxn][maxn];
bool M[maxn][maxn][2];
int dp[maxn][maxn][3];
set<pii> res;
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
if (s[j] == 'R') a[i][j] = 0;
else if (s[j] == 'G') a[i][j] = 1;
else a[i][j] = 2;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m - 2; j++) {
if (a[i][j] == 0 && a[i][j + 1] == 1 && a[i][j + 2] == 2) {
M[i][j + 1][0] = 1;
}
}
}
for (int i = 0; i < n - 2; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == 0 && a[i + 1][j] == 1 && a[i + 2][j] == 2) {
M[i + 1][j][1] = 1;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = m - 1; j >= 0; j--) {
if (!(M[i][j][0] || M[i][j][1])) continue;
dp[i][j][1] = M[i][j][0]; dp[i][j][2] = M[i][j][1];
res.insert(Mp(i, j));
int i1 = i - 1, j1 = j + 1;
if (i1 >= 0 && j1 < m && (M[i1][j1][0] || M[i1][j1][1])) {
dp[i][j][0] = max(dp[i1][j1][0], max(dp[i1][j1][1], dp[i1][j1][2]));
if (M[i][j][0]) {
dp[i][j][1] += max(dp[i1][j1][0], dp[i1][j1][1]);
}
if (M[i][j][1]) {
dp[i][j][2] += max(dp[i1][j1][0], dp[i1][j1][2]);
}
res.erase(Mp(i1, j1));
}
}
}
ll output = 0;
for (auto f : res) {
auto [i, j] = f;
output += max(dp[i][j][0], max(dp[i][j][1], dp[i][j][2]));
}
cout << output << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
328 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 |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
460 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 |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
1 ms |
456 KB |
Output is correct |
37 |
Correct |
0 ms |
424 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
0 ms |
460 KB |
Output is correct |
40 |
Correct |
0 ms |
468 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
328 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 |
336 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
460 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 |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
1 ms |
456 KB |
Output is correct |
37 |
Correct |
0 ms |
424 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
0 ms |
460 KB |
Output is correct |
40 |
Correct |
0 ms |
468 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
0 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
8 ms |
13356 KB |
Output is correct |
56 |
Correct |
2 ms |
724 KB |
Output is correct |
57 |
Correct |
10 ms |
22612 KB |
Output is correct |
58 |
Correct |
47 ms |
33676 KB |
Output is correct |
59 |
Correct |
361 ms |
193684 KB |
Output is correct |
60 |
Correct |
384 ms |
193796 KB |
Output is correct |
61 |
Correct |
365 ms |
193688 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
361 ms |
192704 KB |
Output is correct |
64 |
Correct |
523 ms |
167944 KB |
Output is correct |
65 |
Correct |
521 ms |
167928 KB |
Output is correct |
66 |
Correct |
551 ms |
168012 KB |
Output is correct |
67 |
Correct |
766 ms |
234372 KB |
Output is correct |
68 |
Correct |
716 ms |
233332 KB |
Output is correct |
69 |
Correct |
658 ms |
230860 KB |
Output is correct |
70 |
Correct |
61 ms |
30796 KB |
Output is correct |
71 |
Correct |
63 ms |
30900 KB |
Output is correct |
72 |
Correct |
71 ms |
30848 KB |
Output is correct |
73 |
Correct |
64 ms |
30876 KB |
Output is correct |
74 |
Correct |
63 ms |
30844 KB |
Output is correct |
75 |
Correct |
64 ms |
30812 KB |
Output is correct |
76 |
Correct |
67 ms |
30856 KB |
Output is correct |
77 |
Correct |
65 ms |
30872 KB |
Output is correct |
78 |
Correct |
68 ms |
30936 KB |
Output is correct |
79 |
Correct |
68 ms |
30888 KB |
Output is correct |
80 |
Correct |
65 ms |
30876 KB |
Output is correct |
81 |
Correct |
66 ms |
30912 KB |
Output is correct |
82 |
Correct |
70 ms |
30888 KB |
Output is correct |
83 |
Correct |
71 ms |
30920 KB |
Output is correct |
84 |
Correct |
68 ms |
30828 KB |
Output is correct |
85 |
Correct |
68 ms |
30828 KB |
Output is correct |
86 |
Correct |
64 ms |
30928 KB |
Output is correct |
87 |
Correct |
65 ms |
30876 KB |
Output is correct |
88 |
Correct |
91 ms |
30888 KB |
Output is correct |
89 |
Correct |
65 ms |
30808 KB |
Output is correct |
90 |
Correct |
64 ms |
30924 KB |
Output is correct |