#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define ALL(i) i.begin(),i.end()
#define SZ(i) int(i.size())
#define eb emplace_back
#define X first
#define Y second
#define MEM(i,a) memset(i,(a),sizeof(i))
#ifdef tmd
#define debug(...) fprintf(stderr,"%d(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){
cerr<<x<<",";
_do(y...);
}
#define IOS()
#else
#define debug(...)
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define pary(...)
#define endl '\n'
#endif // tmd
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 3003;
int n, m;
char c[MAXN][MAXN];
bool d[MAXN][MAXN];
bool w[MAXN][MAXN];
int dp[2][3];
bool valid (int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m;
}
int main () {
IOS();
cin >> n >> m;
REP (i, n) {
REP (j, m) {
cin >> c[i][j];
}
}
REP (i, n) {
REP (j, m-2) {
if (c[i][j] == 'R' && c[i][j+1] == 'G' && c[i][j+2] == 'W') {
d[i][j+1] = true;
debug(i, j+1);
}
}
}
REP (j, m) {
REP (i, n-2) {
if (c[i][j] == 'R' && c[i+1][j] == 'G' && c[i+2][j] == 'W') {
w[i+1][j] = true;
debug(i+1, j);
}
}
}
int ans = 0;
REP (i, n+m+4) {
int x = i;
int y = 0;
MEM(dp, 0);
debug(x);
while (x >= 0 && y < m) {
if (valid(x,y) && w[x][y]) {
dp[y&1][1] = max(dp[(y&1)^1][0], dp[(y&1)^1][1]) + 1;
} else {
dp[y&1][1] = 0;
}
if (valid(x,y) && d[x][y]) {
dp[y&1][2] = max(dp[(y&1)^1][0], dp[(y&1)^1][2]) + 1;
} else {
dp[y&1][2] = 0;
}
dp[y&1][0] = max({dp[(y&1)^1][1], dp[(y&1)^1][2], dp[(y&1)^1][0]});
x--;
y++;
}
ans += max({dp[y&1^1][0], dp[y&1^1][1], dp[y&1^1][2]});
}
cout << ans << endl;
return 0;
}
/*
3 4
RGWG
GRGW
RGWR
*/
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:91:25: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
ans += max({dp[y&1^1][0], dp[y&1^1][1], dp[y&1^1][2]});
~^~
dango_maker.cpp:91:39: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
ans += max({dp[y&1^1][0], dp[y&1^1][1], dp[y&1^1][2]});
~^~
dango_maker.cpp:91:53: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
ans += max({dp[y&1^1][0], dp[y&1^1][1], dp[y&1^1][2]});
~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
512 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
4 ms |
384 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
512 KB |
Output is correct |
40 |
Correct |
4 ms |
384 KB |
Output is correct |
41 |
Correct |
4 ms |
384 KB |
Output is correct |
42 |
Correct |
4 ms |
384 KB |
Output is correct |
43 |
Correct |
4 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
384 KB |
Output is correct |
45 |
Correct |
5 ms |
384 KB |
Output is correct |
46 |
Correct |
4 ms |
384 KB |
Output is correct |
47 |
Correct |
4 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
512 KB |
Output is correct |
51 |
Correct |
4 ms |
384 KB |
Output is correct |
52 |
Correct |
4 ms |
384 KB |
Output is correct |
53 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
512 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
384 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
4 ms |
384 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
512 KB |
Output is correct |
40 |
Correct |
4 ms |
384 KB |
Output is correct |
41 |
Correct |
4 ms |
384 KB |
Output is correct |
42 |
Correct |
4 ms |
384 KB |
Output is correct |
43 |
Correct |
4 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
384 KB |
Output is correct |
45 |
Correct |
5 ms |
384 KB |
Output is correct |
46 |
Correct |
4 ms |
384 KB |
Output is correct |
47 |
Correct |
4 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
512 KB |
Output is correct |
51 |
Correct |
4 ms |
384 KB |
Output is correct |
52 |
Correct |
4 ms |
384 KB |
Output is correct |
53 |
Correct |
4 ms |
384 KB |
Output is correct |
54 |
Correct |
22 ms |
384 KB |
Output is correct |
55 |
Correct |
11 ms |
9600 KB |
Output is correct |
56 |
Correct |
23 ms |
384 KB |
Output is correct |
57 |
Correct |
11 ms |
14592 KB |
Output is correct |
58 |
Correct |
44 ms |
10112 KB |
Output is correct |
59 |
Correct |
411 ms |
35576 KB |
Output is correct |
60 |
Correct |
406 ms |
35704 KB |
Output is correct |
61 |
Correct |
399 ms |
35576 KB |
Output is correct |
62 |
Correct |
20 ms |
384 KB |
Output is correct |
63 |
Correct |
412 ms |
35576 KB |
Output is correct |
64 |
Correct |
363 ms |
35576 KB |
Output is correct |
65 |
Correct |
362 ms |
35832 KB |
Output is correct |
66 |
Correct |
354 ms |
35576 KB |
Output is correct |
67 |
Correct |
349 ms |
25176 KB |
Output is correct |
68 |
Correct |
346 ms |
25080 KB |
Output is correct |
69 |
Correct |
351 ms |
31492 KB |
Output is correct |
70 |
Correct |
34 ms |
10104 KB |
Output is correct |
71 |
Correct |
39 ms |
10112 KB |
Output is correct |
72 |
Correct |
35 ms |
10112 KB |
Output is correct |
73 |
Correct |
35 ms |
10104 KB |
Output is correct |
74 |
Correct |
35 ms |
10240 KB |
Output is correct |
75 |
Correct |
34 ms |
10112 KB |
Output is correct |
76 |
Correct |
37 ms |
10104 KB |
Output is correct |
77 |
Correct |
35 ms |
10112 KB |
Output is correct |
78 |
Correct |
41 ms |
10232 KB |
Output is correct |
79 |
Correct |
35 ms |
10240 KB |
Output is correct |
80 |
Correct |
34 ms |
10112 KB |
Output is correct |
81 |
Correct |
39 ms |
10368 KB |
Output is correct |
82 |
Correct |
36 ms |
10112 KB |
Output is correct |
83 |
Correct |
35 ms |
10112 KB |
Output is correct |
84 |
Correct |
40 ms |
10112 KB |
Output is correct |
85 |
Correct |
34 ms |
10104 KB |
Output is correct |
86 |
Correct |
34 ms |
10112 KB |
Output is correct |
87 |
Correct |
34 ms |
10112 KB |
Output is correct |
88 |
Correct |
37 ms |
10232 KB |
Output is correct |
89 |
Correct |
35 ms |
10232 KB |
Output is correct |
90 |
Correct |
34 ms |
10112 KB |
Output is correct |