#include <iostream>
#include <vector>
using namespace std;
int n, m;
vector<string> g;
vector<pair<int, int>> getDiagonalCoords(int i, int j) {
vector<pair<int, int>> ret;
while (i < n and j > -1) {
ret.push_back({i, j});
i++, j--;
}
return ret;
}
int solve(int bad, int idx, vector<vector<int>> &dp, vector<pair<int, int>> &coords) {
if (idx >= coords.size()) return 0;
if (dp[bad][idx] != -1) return dp[bad][idx];
int i = coords[idx].first, j = coords[idx].second;
int &ret = dp[bad][idx];
ret = solve(max(0, bad - 1), idx + 1, dp, coords);
if (i + 2 < n and g[i][j] == 'R' and g[i + 1][j] == 'G' and g[i + 2][j] == 'W') {
ret = max(ret, 1 + solve(2, idx + 1, dp, coords));
}
if (not bad and j + 2 < m and g[i][j] == 'R' and g[i][j + 1] == 'G' and g[i][j + 2] == 'W') {
ret = max(ret, 1 + solve(0, idx + 1, dp, coords));
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
g.resize(n);
for (int i = 0; i < n; i++) {
cin >> g[i];
}
int ans = 0;
for (int j = 0; j < m; j++) {
vector<pair<int, int>> coords = getDiagonalCoords(0, j);
vector<vector<int>> dp(3, vector<int>(coords.size(), -1));
ans += solve(0, 0, dp, coords);
}
for (int i = 1; i < n; i++) {
vector<pair<int, int>> coords = getDiagonalCoords(i, m - 1);
vector<vector<int>> dp(3, vector<int>(coords.size(), -1));
ans += solve(0, 0, dp, coords);
}
cout << ans << '\n';
return 0;
}
Compilation message
dango_maker.cpp: In function 'int solve(int, int, std::vector<std::vector<int> >&, std::vector<std::pair<int, int> >&)':
dango_maker.cpp:18:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if (idx >= coords.size()) return 0;
| ~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
0 ms |
212 KB |
Output is correct |
53 |
Correct |
0 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
2 ms |
340 KB |
Output is correct |
58 |
Correct |
33 ms |
1592 KB |
Output is correct |
59 |
Correct |
324 ms |
10544 KB |
Output is correct |
60 |
Correct |
317 ms |
10608 KB |
Output is correct |
61 |
Correct |
351 ms |
10572 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
307 ms |
10244 KB |
Output is correct |
64 |
Correct |
352 ms |
10664 KB |
Output is correct |
65 |
Correct |
374 ms |
10568 KB |
Output is correct |
66 |
Correct |
358 ms |
10680 KB |
Output is correct |
67 |
Correct |
328 ms |
10608 KB |
Output is correct |
68 |
Correct |
300 ms |
10568 KB |
Output is correct |
69 |
Correct |
354 ms |
10528 KB |
Output is correct |
70 |
Correct |
33 ms |
1620 KB |
Output is correct |
71 |
Correct |
33 ms |
1620 KB |
Output is correct |
72 |
Correct |
34 ms |
1592 KB |
Output is correct |
73 |
Correct |
34 ms |
1620 KB |
Output is correct |
74 |
Correct |
37 ms |
1636 KB |
Output is correct |
75 |
Correct |
33 ms |
1584 KB |
Output is correct |
76 |
Correct |
35 ms |
1620 KB |
Output is correct |
77 |
Correct |
33 ms |
1536 KB |
Output is correct |
78 |
Correct |
35 ms |
1616 KB |
Output is correct |
79 |
Correct |
32 ms |
1624 KB |
Output is correct |
80 |
Correct |
32 ms |
1612 KB |
Output is correct |
81 |
Correct |
38 ms |
1604 KB |
Output is correct |
82 |
Correct |
32 ms |
1620 KB |
Output is correct |
83 |
Correct |
32 ms |
1592 KB |
Output is correct |
84 |
Correct |
43 ms |
1520 KB |
Output is correct |
85 |
Correct |
33 ms |
1588 KB |
Output is correct |
86 |
Correct |
35 ms |
1620 KB |
Output is correct |
87 |
Correct |
32 ms |
1620 KB |
Output is correct |
88 |
Correct |
34 ms |
1612 KB |
Output is correct |
89 |
Correct |
35 ms |
1612 KB |
Output is correct |
90 |
Correct |
36 ms |
1592 KB |
Output is correct |