#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
const ll mxn = 1e6 + 5;
const int INF = 1e9 + 9;
void solve() {
ll n, m;
cin >> n >> m;
vector<vector<char>> a(n+1, vector<char>(m+1));
vector<vec> dp(mxn, vec(3, 0));
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
ll ans = 0;
for (ll k = 2; k <= n + m; k++) {
for (ll i = 0; i <= n; i++)
for (ll j = 0; j < 3; j++)
dp[i][j] = 0;
ll j = min(k - 1, m), i = k - j;
int cnt = 0;
while (i <= n && j >= 1 && j <= m) {
dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
if (j > 1 && j < m && a[i][j] == 'G' && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
}
if (i > 1 && i < n && a[i][j] == 'G' && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
dp[i][2] = max(dp[i - 1][0], dp[i - 1][2]) + 1;
}
i++; j--;
}
ans += max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
Compilation message
dango_maker.cpp: In function 'void solve()':
dango_maker.cpp:30:13: warning: unused variable 'cnt' [-Wunused-variable]
30 | int cnt = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
55000 KB |
Output is correct |
2 |
Correct |
42 ms |
55008 KB |
Output is correct |
3 |
Correct |
47 ms |
55120 KB |
Output is correct |
4 |
Correct |
43 ms |
55124 KB |
Output is correct |
5 |
Correct |
44 ms |
55128 KB |
Output is correct |
6 |
Correct |
43 ms |
55128 KB |
Output is correct |
7 |
Correct |
44 ms |
55124 KB |
Output is correct |
8 |
Correct |
49 ms |
55120 KB |
Output is correct |
9 |
Correct |
44 ms |
55120 KB |
Output is correct |
10 |
Correct |
46 ms |
55216 KB |
Output is correct |
11 |
Correct |
48 ms |
55120 KB |
Output is correct |
12 |
Correct |
42 ms |
55124 KB |
Output is correct |
13 |
Correct |
45 ms |
55124 KB |
Output is correct |
14 |
Correct |
45 ms |
55008 KB |
Output is correct |
15 |
Correct |
52 ms |
55124 KB |
Output is correct |
16 |
Correct |
47 ms |
55212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
55000 KB |
Output is correct |
2 |
Correct |
42 ms |
55008 KB |
Output is correct |
3 |
Correct |
47 ms |
55120 KB |
Output is correct |
4 |
Correct |
43 ms |
55124 KB |
Output is correct |
5 |
Correct |
44 ms |
55128 KB |
Output is correct |
6 |
Correct |
43 ms |
55128 KB |
Output is correct |
7 |
Correct |
44 ms |
55124 KB |
Output is correct |
8 |
Correct |
49 ms |
55120 KB |
Output is correct |
9 |
Correct |
44 ms |
55120 KB |
Output is correct |
10 |
Correct |
46 ms |
55216 KB |
Output is correct |
11 |
Correct |
48 ms |
55120 KB |
Output is correct |
12 |
Correct |
42 ms |
55124 KB |
Output is correct |
13 |
Correct |
45 ms |
55124 KB |
Output is correct |
14 |
Correct |
45 ms |
55008 KB |
Output is correct |
15 |
Correct |
52 ms |
55124 KB |
Output is correct |
16 |
Correct |
47 ms |
55212 KB |
Output is correct |
17 |
Correct |
44 ms |
55132 KB |
Output is correct |
18 |
Correct |
45 ms |
55096 KB |
Output is correct |
19 |
Correct |
45 ms |
55120 KB |
Output is correct |
20 |
Correct |
40 ms |
55124 KB |
Output is correct |
21 |
Correct |
42 ms |
55124 KB |
Output is correct |
22 |
Correct |
43 ms |
55120 KB |
Output is correct |
23 |
Correct |
39 ms |
55108 KB |
Output is correct |
24 |
Correct |
40 ms |
55120 KB |
Output is correct |
25 |
Correct |
40 ms |
55116 KB |
Output is correct |
26 |
Correct |
40 ms |
55124 KB |
Output is correct |
27 |
Correct |
50 ms |
55172 KB |
Output is correct |
28 |
Correct |
40 ms |
55212 KB |
Output is correct |
29 |
Correct |
40 ms |
55132 KB |
Output is correct |
30 |
Correct |
39 ms |
55124 KB |
Output is correct |
31 |
Correct |
55 ms |
55220 KB |
Output is correct |
32 |
Correct |
46 ms |
55092 KB |
Output is correct |
33 |
Correct |
45 ms |
55124 KB |
Output is correct |
34 |
Correct |
40 ms |
55120 KB |
Output is correct |
35 |
Correct |
52 ms |
55120 KB |
Output is correct |
36 |
Correct |
40 ms |
55132 KB |
Output is correct |
37 |
Correct |
39 ms |
55132 KB |
Output is correct |
38 |
Correct |
39 ms |
55084 KB |
Output is correct |
39 |
Correct |
40 ms |
55120 KB |
Output is correct |
40 |
Correct |
42 ms |
55124 KB |
Output is correct |
41 |
Correct |
60 ms |
55032 KB |
Output is correct |
42 |
Correct |
53 ms |
55124 KB |
Output is correct |
43 |
Correct |
43 ms |
55120 KB |
Output is correct |
44 |
Correct |
41 ms |
55352 KB |
Output is correct |
45 |
Correct |
49 ms |
55108 KB |
Output is correct |
46 |
Correct |
42 ms |
55124 KB |
Output is correct |
47 |
Correct |
56 ms |
55124 KB |
Output is correct |
48 |
Correct |
42 ms |
55016 KB |
Output is correct |
49 |
Correct |
41 ms |
55152 KB |
Output is correct |
50 |
Correct |
43 ms |
55124 KB |
Output is correct |
51 |
Correct |
40 ms |
55012 KB |
Output is correct |
52 |
Correct |
49 ms |
55216 KB |
Output is correct |
53 |
Correct |
40 ms |
55124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
55000 KB |
Output is correct |
2 |
Correct |
42 ms |
55008 KB |
Output is correct |
3 |
Correct |
47 ms |
55120 KB |
Output is correct |
4 |
Correct |
43 ms |
55124 KB |
Output is correct |
5 |
Correct |
44 ms |
55128 KB |
Output is correct |
6 |
Correct |
43 ms |
55128 KB |
Output is correct |
7 |
Correct |
44 ms |
55124 KB |
Output is correct |
8 |
Correct |
49 ms |
55120 KB |
Output is correct |
9 |
Correct |
44 ms |
55120 KB |
Output is correct |
10 |
Correct |
46 ms |
55216 KB |
Output is correct |
11 |
Correct |
48 ms |
55120 KB |
Output is correct |
12 |
Correct |
42 ms |
55124 KB |
Output is correct |
13 |
Correct |
45 ms |
55124 KB |
Output is correct |
14 |
Correct |
45 ms |
55008 KB |
Output is correct |
15 |
Correct |
52 ms |
55124 KB |
Output is correct |
16 |
Correct |
47 ms |
55212 KB |
Output is correct |
17 |
Correct |
44 ms |
55132 KB |
Output is correct |
18 |
Correct |
45 ms |
55096 KB |
Output is correct |
19 |
Correct |
45 ms |
55120 KB |
Output is correct |
20 |
Correct |
40 ms |
55124 KB |
Output is correct |
21 |
Correct |
42 ms |
55124 KB |
Output is correct |
22 |
Correct |
43 ms |
55120 KB |
Output is correct |
23 |
Correct |
39 ms |
55108 KB |
Output is correct |
24 |
Correct |
40 ms |
55120 KB |
Output is correct |
25 |
Correct |
40 ms |
55116 KB |
Output is correct |
26 |
Correct |
40 ms |
55124 KB |
Output is correct |
27 |
Correct |
50 ms |
55172 KB |
Output is correct |
28 |
Correct |
40 ms |
55212 KB |
Output is correct |
29 |
Correct |
40 ms |
55132 KB |
Output is correct |
30 |
Correct |
39 ms |
55124 KB |
Output is correct |
31 |
Correct |
55 ms |
55220 KB |
Output is correct |
32 |
Correct |
46 ms |
55092 KB |
Output is correct |
33 |
Correct |
45 ms |
55124 KB |
Output is correct |
34 |
Correct |
40 ms |
55120 KB |
Output is correct |
35 |
Correct |
52 ms |
55120 KB |
Output is correct |
36 |
Correct |
40 ms |
55132 KB |
Output is correct |
37 |
Correct |
39 ms |
55132 KB |
Output is correct |
38 |
Correct |
39 ms |
55084 KB |
Output is correct |
39 |
Correct |
40 ms |
55120 KB |
Output is correct |
40 |
Correct |
42 ms |
55124 KB |
Output is correct |
41 |
Correct |
60 ms |
55032 KB |
Output is correct |
42 |
Correct |
53 ms |
55124 KB |
Output is correct |
43 |
Correct |
43 ms |
55120 KB |
Output is correct |
44 |
Correct |
41 ms |
55352 KB |
Output is correct |
45 |
Correct |
49 ms |
55108 KB |
Output is correct |
46 |
Correct |
42 ms |
55124 KB |
Output is correct |
47 |
Correct |
56 ms |
55124 KB |
Output is correct |
48 |
Correct |
42 ms |
55016 KB |
Output is correct |
49 |
Correct |
41 ms |
55152 KB |
Output is correct |
50 |
Correct |
43 ms |
55124 KB |
Output is correct |
51 |
Correct |
40 ms |
55012 KB |
Output is correct |
52 |
Correct |
49 ms |
55216 KB |
Output is correct |
53 |
Correct |
40 ms |
55124 KB |
Output is correct |
54 |
Correct |
45 ms |
55188 KB |
Output is correct |
55 |
Correct |
49 ms |
55308 KB |
Output is correct |
56 |
Correct |
47 ms |
55120 KB |
Output is correct |
57 |
Correct |
44 ms |
55128 KB |
Output is correct |
58 |
Correct |
74 ms |
57112 KB |
Output is correct |
59 |
Correct |
206 ms |
72860 KB |
Output is correct |
60 |
Correct |
215 ms |
72752 KB |
Output is correct |
61 |
Correct |
214 ms |
72948 KB |
Output is correct |
62 |
Correct |
41 ms |
55120 KB |
Output is correct |
63 |
Correct |
218 ms |
72272 KB |
Output is correct |
64 |
Correct |
177 ms |
72788 KB |
Output is correct |
65 |
Correct |
165 ms |
72788 KB |
Output is correct |
66 |
Correct |
161 ms |
72880 KB |
Output is correct |
67 |
Correct |
154 ms |
72852 KB |
Output is correct |
68 |
Correct |
159 ms |
72788 KB |
Output is correct |
69 |
Correct |
156 ms |
72788 KB |
Output is correct |
70 |
Correct |
59 ms |
57136 KB |
Output is correct |
71 |
Correct |
55 ms |
57172 KB |
Output is correct |
72 |
Correct |
54 ms |
57172 KB |
Output is correct |
73 |
Correct |
61 ms |
57040 KB |
Output is correct |
74 |
Correct |
75 ms |
57148 KB |
Output is correct |
75 |
Correct |
60 ms |
57172 KB |
Output is correct |
76 |
Correct |
54 ms |
57172 KB |
Output is correct |
77 |
Correct |
54 ms |
57168 KB |
Output is correct |
78 |
Correct |
61 ms |
57168 KB |
Output is correct |
79 |
Correct |
58 ms |
57172 KB |
Output is correct |
80 |
Correct |
59 ms |
57172 KB |
Output is correct |
81 |
Correct |
56 ms |
57168 KB |
Output is correct |
82 |
Correct |
57 ms |
57228 KB |
Output is correct |
83 |
Correct |
67 ms |
57104 KB |
Output is correct |
84 |
Correct |
57 ms |
57120 KB |
Output is correct |
85 |
Correct |
57 ms |
57164 KB |
Output is correct |
86 |
Correct |
59 ms |
57168 KB |
Output is correct |
87 |
Correct |
58 ms |
57168 KB |
Output is correct |
88 |
Correct |
67 ms |
57172 KB |
Output is correct |
89 |
Correct |
57 ms |
57172 KB |
Output is correct |
90 |
Correct |
59 ms |
57172 KB |
Output is correct |