#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}
typedef int int2;
#define int long long
#define pi pair<int, int>
#define vi vector<int>
#define vii vector<vector<int>>
#define vpi vector<pi>
#define lep(i,l,r) for(int i=l;i<=r;++i)
#define rep(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
const int inf = 1e18;
int t;
typedef array<int,2> a2;
int2 main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<string> a(n);
lep(i,0,n-1) {
cin >> a[i];
}
vector<vector<a2>> dp(n, vector<a2>(m));
vector<vector<bool>> can0(n, vector<bool>(m)); // horiz
vector<vector<bool>> can1 = can0; // vertical
lep(i,0,n-1) {
rep(j,m-1,0) {
if (j + 2 < m and a[i][j] == 'R' and a[i][j+1] == 'G' and a[i][j+2] == 'W') can0[i][j] = true;
if (i + 2 < n and a[i][j] == 'R' and a[i+1][j] == 'G' and a[i+2][j] == 'W') can1[i][j] = true;
if (i == 0 or j == m - 1) {
// base case
if (can0[i][j]) dp[i][j][0] = 1;
if (can1[i][j]) dp[i][j][1] = 1;
} else {
int dp0 = dp[i-1][j+1][0]; // horizontal
if (can0[i][j]) {
dp0 = max(dp0, 1LL);
// place a horizontal thing here
dp0 = max(dp0, 1 + dp[i-1][j+1][0]); // place horizontal thing earlier
// place vertical thing 3 earlier
if (i-3 >= 0 and j+3 < m) {
dp0 = max(dp0, 1 + dp[i-3][j+3][1]);
}
}
int dp1 = dp[i-1][j+1][1];
if (can1[i][j]) {
dp1 = max(dp1, 1LL);
// place a vertical thing here. no restrictions on others
dp1 = max(dp1, 1 + max(dp[i-1][j+1][0], dp[i-1][j+1][1]));
}
dp[i][j][0] = dp0;
dp[i][j][1] = dp1;
}
}
}
DEBUG(can1[0][3], can1[1][2]);
DEBUG(dp[0][3]);
DEBUG(dp[1][2]);
DEBUG(dp[1][2][1]);
int ans = 0;
lep(i,0,n-1) {
lep(j,0,m-1) {
if (j == 0 or i == n-1) {
int to_add = max(dp[i][j][0], dp[i][j][1]);
DEBUG(i,j,to_add);
ans += max(dp[i][j][0], dp[i][j][1]);
}
}
}
cout << ans << "\n";
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Compilation message
dango_maker.cpp: In function 'int2 main()':
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
8 | #define DEBUG(...) 6
| ^
dango_maker.cpp:80:5: note: in expansion of macro 'DEBUG'
80 | DEBUG(can1[0][3], can1[1][2]);
| ^~~~~
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
8 | #define DEBUG(...) 6
| ^
dango_maker.cpp:81:5: note: in expansion of macro 'DEBUG'
81 | DEBUG(dp[0][3]);
| ^~~~~
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
8 | #define DEBUG(...) 6
| ^
dango_maker.cpp:82:5: note: in expansion of macro 'DEBUG'
82 | DEBUG(dp[1][2]);
| ^~~~~
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
8 | #define DEBUG(...) 6
| ^
dango_maker.cpp:83:5: note: in expansion of macro 'DEBUG'
83 | DEBUG(dp[1][2][1]);
| ^~~~~
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
8 | #define DEBUG(...) 6
| ^
dango_maker.cpp:89:17: note: in expansion of macro 'DEBUG'
89 | DEBUG(i,j,to_add);
| ^~~~~
dango_maker.cpp:88:21: warning: unused variable 'to_add' [-Wunused-variable]
88 | int to_add = max(dp[i][j][0], dp[i][j][1]);
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
508 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
508 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
476 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 |
508 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 |
1 ms |
352 KB |
Output is correct |
34 |
Correct |
1 ms |
352 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 |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
504 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 |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
504 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
460 KB |
Output is correct |
53 |
Correct |
1 ms |
532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
508 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
476 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 |
508 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 |
1 ms |
352 KB |
Output is correct |
34 |
Correct |
1 ms |
352 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 |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
1 ms |
504 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 |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
504 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
460 KB |
Output is correct |
53 |
Correct |
1 ms |
532 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
2 ms |
1108 KB |
Output is correct |
56 |
Correct |
2 ms |
596 KB |
Output is correct |
57 |
Correct |
2 ms |
1108 KB |
Output is correct |
58 |
Correct |
23 ms |
18360 KB |
Output is correct |
59 |
Correct |
219 ms |
162620 KB |
Output is correct |
60 |
Correct |
227 ms |
162528 KB |
Output is correct |
61 |
Correct |
202 ms |
162448 KB |
Output is correct |
62 |
Correct |
1 ms |
596 KB |
Output is correct |
63 |
Correct |
218 ms |
157120 KB |
Output is correct |
64 |
Correct |
164 ms |
162380 KB |
Output is correct |
65 |
Correct |
177 ms |
162380 KB |
Output is correct |
66 |
Correct |
169 ms |
162444 KB |
Output is correct |
67 |
Correct |
161 ms |
162376 KB |
Output is correct |
68 |
Correct |
166 ms |
162360 KB |
Output is correct |
69 |
Correct |
174 ms |
162380 KB |
Output is correct |
70 |
Correct |
19 ms |
18516 KB |
Output is correct |
71 |
Correct |
20 ms |
18516 KB |
Output is correct |
72 |
Correct |
19 ms |
18516 KB |
Output is correct |
73 |
Correct |
25 ms |
18516 KB |
Output is correct |
74 |
Correct |
20 ms |
18516 KB |
Output is correct |
75 |
Correct |
19 ms |
18516 KB |
Output is correct |
76 |
Correct |
19 ms |
18516 KB |
Output is correct |
77 |
Correct |
20 ms |
18516 KB |
Output is correct |
78 |
Correct |
19 ms |
18516 KB |
Output is correct |
79 |
Correct |
20 ms |
18516 KB |
Output is correct |
80 |
Correct |
19 ms |
18516 KB |
Output is correct |
81 |
Correct |
19 ms |
18516 KB |
Output is correct |
82 |
Correct |
19 ms |
18516 KB |
Output is correct |
83 |
Correct |
25 ms |
18516 KB |
Output is correct |
84 |
Correct |
19 ms |
18516 KB |
Output is correct |
85 |
Correct |
23 ms |
18508 KB |
Output is correct |
86 |
Correct |
19 ms |
18680 KB |
Output is correct |
87 |
Correct |
17 ms |
18452 KB |
Output is correct |
88 |
Correct |
17 ms |
18516 KB |
Output is correct |
89 |
Correct |
17 ms |
18456 KB |
Output is correct |
90 |
Correct |
17 ms |
18516 KB |
Output is correct |