#include <bits/stdc++.h>
using namespace std;
int dp[6004][3005][3];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin >> n >> m;
vector<string> graph(n);
for (int i = 0; i < n; i++) {
cin >> graph[i];
}
vector<vector<pair<int, int>>> skewers(n, vector<pair<int, int>>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i > 0 && i < n - 1 && graph[i][j] == 'G' && graph[i - 1][j] == 'R' && graph[i + 1][j] == 'W') {
skewers[i][j].first = 1;
}
if (j > 0 && j < m - 1 && graph[i][j] == 'G' && graph[i][j - 1] == 'R' && graph[i][j + 1] == 'W') {
skewers[i][j].second = 1;
}
}
}
for (int j = 0; j < n + m - 1; j++) {
int curx = min(j, m-1);
int cury = j - curx;
while (curx >= 0 && cury < n) {
int last=0;
if (cury == 0) {
last = 0;
} else {
last = max({dp[j][cury - 1][0], dp[j][cury - 1][1], dp[j][cury - 1][2]});
}
dp[j][cury][0] = last;
if (skewers[cury][curx].first == 1) {
int last = 0;
if (cury == 0) {
last = 0;
} else {
last = max({dp[j][cury - 1][0], dp[j][cury - 1][1], dp[j][cury - 1][2]});
}
dp[j][cury][0] = last;
if (cury == 0) {
last = 0;
} else {
last = max({dp[j][cury - 1][0], dp[j][cury - 1][1]});
}
dp[j][cury][1] = last + 1;
}
if (skewers[cury][curx].second == 1) {
int last;
if (cury == 0) {
last = 0;
} else {
last = max({dp[j][cury - 1][0], dp[j][cury - 1][1], dp[j][cury - 1][2]});
}
dp[j][cury][0] = last;
if (cury == 0) {
last = 0;
} else {
last = max({dp[j][cury - 1][0], dp[j][cury - 1][2]});
}
dp[j][cury][2] = last + 1;
}
cury++;
curx--;
}
}
long long res = 0;
int lol = 0;
for (int i = 0; i < n + m - 1; i++) {
res = res+max({dp[i][lol][0], dp[i][lol][1], dp[i][lol][2]});
lol = min(lol + 1, n-1);
}
cout << res << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2516 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
2516 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
0 ms |
2396 KB |
Output is correct |
51 |
Correct |
1 ms |
2396 KB |
Output is correct |
52 |
Correct |
1 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
0 ms |
2516 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
2516 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
0 ms |
2396 KB |
Output is correct |
51 |
Correct |
1 ms |
2396 KB |
Output is correct |
52 |
Correct |
1 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
23 ms |
107088 KB |
Output is correct |
55 |
Correct |
6 ms |
12892 KB |
Output is correct |
56 |
Correct |
11 ms |
107352 KB |
Output is correct |
57 |
Correct |
5 ms |
10844 KB |
Output is correct |
58 |
Correct |
28 ms |
56400 KB |
Output is correct |
59 |
Correct |
219 ms |
253876 KB |
Output is correct |
60 |
Correct |
228 ms |
254060 KB |
Output is correct |
61 |
Correct |
218 ms |
253008 KB |
Output is correct |
62 |
Correct |
11 ms |
100956 KB |
Output is correct |
63 |
Correct |
208 ms |
248656 KB |
Output is correct |
64 |
Correct |
167 ms |
258900 KB |
Output is correct |
65 |
Correct |
176 ms |
258804 KB |
Output is correct |
66 |
Correct |
175 ms |
258856 KB |
Output is correct |
67 |
Correct |
167 ms |
256636 KB |
Output is correct |
68 |
Correct |
166 ms |
256596 KB |
Output is correct |
69 |
Correct |
187 ms |
256620 KB |
Output is correct |
70 |
Correct |
23 ms |
57936 KB |
Output is correct |
71 |
Correct |
23 ms |
57844 KB |
Output is correct |
72 |
Correct |
23 ms |
57936 KB |
Output is correct |
73 |
Correct |
23 ms |
57812 KB |
Output is correct |
74 |
Correct |
23 ms |
57940 KB |
Output is correct |
75 |
Correct |
24 ms |
57948 KB |
Output is correct |
76 |
Correct |
23 ms |
57936 KB |
Output is correct |
77 |
Correct |
22 ms |
57848 KB |
Output is correct |
78 |
Correct |
23 ms |
57972 KB |
Output is correct |
79 |
Correct |
24 ms |
57940 KB |
Output is correct |
80 |
Correct |
25 ms |
57940 KB |
Output is correct |
81 |
Correct |
23 ms |
57936 KB |
Output is correct |
82 |
Correct |
22 ms |
57996 KB |
Output is correct |
83 |
Correct |
24 ms |
57860 KB |
Output is correct |
84 |
Correct |
23 ms |
57948 KB |
Output is correct |
85 |
Correct |
23 ms |
57948 KB |
Output is correct |
86 |
Correct |
24 ms |
57948 KB |
Output is correct |
87 |
Correct |
24 ms |
57948 KB |
Output is correct |
88 |
Correct |
22 ms |
57936 KB |
Output is correct |
89 |
Correct |
23 ms |
57944 KB |
Output is correct |
90 |
Correct |
23 ms |
58032 KB |
Output is correct |