#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
#else
#define debug(args...)
#endif
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 3005
int n, m;
char s[MAXN][MAXN];
int dp[MAXN][MAXN][5];
int ans;
bool rgw(int i, int j, bool isc) {
if (!isc) {
if (j + 2 >= m) return 0;
if (s[i][j] == 'R' && s[i][j + 1] == 'G' && s[i][j + 2] == 'W') {
return 1;
}
return 0;
} else {
if (i + 2 >= n) return 0;
if (s[i][j] == 'R' && s[i + 1][j] == 'G' && s[i + 2][j] == 'W') {
return 1;
}
return 0;
}
assert(0);
}
int main() {
scanf("%d%d", &n, &m);
REP (i, 0, n) {
scanf(" %s", s[i]);
}
int pi = 0, pj = 0;
dp[0][0][0] = dp[0][0][1] = dp[0][0][2] = max(rgw(0, 0, 0), rgw(0, 0, 1));
REP (ij, 1, n + m - 1) {
REP (i, 0, ij + 1) {
int j = ij - i;
if (i >= n || j >= m) continue;
dp[i][j][0] = dp[pi][pj][0];
if (rgw(i, j, 0)) {
dp[i][j][0] = dp[pi][pj][0] + 1;
}
if (rgw(i, j, 1)) {
dp[i][j][2] = max(dp[pi][pj][0],
max(dp[pi][pj][1], dp[pi][pj][2])) + 1;
}
if (i != 0) {
REP (k, 1, 3) {
mxto(dp[i][j][k - 1], dp[pi][pj][k]);
}
}
if (j == 0) {
int tmp = 0;
REP (k, 0, 3) {
mxto(tmp, dp[i][j][k]);
}
REP (k, 0, 3) {
dp[i][j][k] = tmp;
}
}
debug("%d %d\n", i, j);
REP (k, 0, 3) {
debug(" %d: %d\n", k, dp[i][j][k]);
mxto(ans, dp[i][j][k]);
}
pi = i; pj = j;
}
}
printf("%d\n", ans);
return 0;
}
/*
3 4
RGWR
GRGG
RGWW
4 4
RGWR
GRRG
WGGW
WWWR
5 5
RGRGW
GRRGW
WGGWR
RWRGW
RGWGW
*/
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
dango_maker.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | scanf(" %s", s[i]);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
0 ms |
332 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
0 ms |
332 KB |
Output is correct |
45 |
Correct |
0 ms |
332 KB |
Output is correct |
46 |
Correct |
0 ms |
332 KB |
Output is correct |
47 |
Correct |
0 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
0 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
1 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
0 ms |
332 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
0 ms |
332 KB |
Output is correct |
45 |
Correct |
0 ms |
332 KB |
Output is correct |
46 |
Correct |
0 ms |
332 KB |
Output is correct |
47 |
Correct |
0 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
0 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
1 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
1 ms |
332 KB |
Output is correct |
54 |
Correct |
6 ms |
360 KB |
Output is correct |
55 |
Correct |
14 ms |
21452 KB |
Output is correct |
56 |
Correct |
6 ms |
588 KB |
Output is correct |
57 |
Correct |
9 ms |
14668 KB |
Output is correct |
58 |
Correct |
58 ms |
26804 KB |
Output is correct |
59 |
Correct |
485 ms |
185504 KB |
Output is correct |
60 |
Correct |
488 ms |
194268 KB |
Output is correct |
61 |
Correct |
481 ms |
194384 KB |
Output is correct |
62 |
Correct |
5 ms |
332 KB |
Output is correct |
63 |
Correct |
471 ms |
194052 KB |
Output is correct |
64 |
Correct |
448 ms |
194256 KB |
Output is correct |
65 |
Correct |
463 ms |
194300 KB |
Output is correct |
66 |
Correct |
438 ms |
194272 KB |
Output is correct |
67 |
Correct |
449 ms |
194244 KB |
Output is correct |
68 |
Correct |
475 ms |
194288 KB |
Output is correct |
69 |
Correct |
453 ms |
194296 KB |
Output is correct |
70 |
Correct |
43 ms |
27716 KB |
Output is correct |
71 |
Correct |
42 ms |
27812 KB |
Output is correct |
72 |
Correct |
43 ms |
27804 KB |
Output is correct |
73 |
Correct |
44 ms |
27808 KB |
Output is correct |
74 |
Correct |
44 ms |
27764 KB |
Output is correct |
75 |
Correct |
45 ms |
27812 KB |
Output is correct |
76 |
Correct |
39 ms |
27808 KB |
Output is correct |
77 |
Correct |
40 ms |
27752 KB |
Output is correct |
78 |
Correct |
41 ms |
27716 KB |
Output is correct |
79 |
Correct |
41 ms |
27724 KB |
Output is correct |
80 |
Correct |
41 ms |
27764 KB |
Output is correct |
81 |
Correct |
41 ms |
27824 KB |
Output is correct |
82 |
Correct |
42 ms |
27716 KB |
Output is correct |
83 |
Correct |
41 ms |
27772 KB |
Output is correct |
84 |
Correct |
41 ms |
27800 KB |
Output is correct |
85 |
Correct |
40 ms |
27796 KB |
Output is correct |
86 |
Correct |
44 ms |
27744 KB |
Output is correct |
87 |
Correct |
41 ms |
27736 KB |
Output is correct |
88 |
Correct |
44 ms |
27760 KB |
Output is correct |
89 |
Correct |
47 ms |
27716 KB |
Output is correct |
90 |
Correct |
40 ms |
27788 KB |
Output is correct |