#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 3005;
int ok[N][N];
char str[N][N];
int dp[N][3];
int n,m;
int main(void) {
cin>>n>>m;
for (int i = 1;i <= n;++i)
cin>>(str[i] + 1);
for (int i = 1;i <= n;++i)
for (int j = 1;j <= m;++j) {
if (str[i - 1][j] == 'R' && str[i][j] == 'G' && str[i + 1][j] == 'W')
ok[i][j] |= 1;
if (str[i][j - 1] == 'R' && str[i][j] == 'G' && str[i][j + 1] == 'W')
ok[i][j] |= 2;
}
int ans = 0;
for (int sum = 1;sum <= n + m;++sum) {
int rem = 0;
for (int i = 1;i <= n;++i)
for (int t = 0;t < 3;++t)
dp[i][t] = 0;
for (int i = 1;i <= n;++i) {
if (1 <= sum - i && sum - i <= m) {
if (ok[i][sum - i] & 1) {
smax(dp[i][1],1 + max(dp[i - 1][1],dp[i - 1][0]));
}
if (ok[i][sum - i] & 2) {
smax(dp[i][2],1 + max(dp[i - 1][2],dp[i - 1][0]));
}
smax(dp[i][0],max({dp[i - 1][0],dp[i - 1][1],dp[i - 1][2]}));
}
smax(rem,max({dp[i][0],dp[i][1],dp[i][2]}));
}
ans += rem;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
692 KB |
Output is correct |
5 |
Correct |
2 ms |
692 KB |
Output is correct |
6 |
Correct |
2 ms |
692 KB |
Output is correct |
7 |
Correct |
3 ms |
692 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
4 ms |
692 KB |
Output is correct |
10 |
Correct |
3 ms |
728 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
3 ms |
728 KB |
Output is correct |
13 |
Correct |
3 ms |
728 KB |
Output is correct |
14 |
Correct |
4 ms |
728 KB |
Output is correct |
15 |
Correct |
3 ms |
796 KB |
Output is correct |
16 |
Correct |
3 ms |
796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
692 KB |
Output is correct |
5 |
Correct |
2 ms |
692 KB |
Output is correct |
6 |
Correct |
2 ms |
692 KB |
Output is correct |
7 |
Correct |
3 ms |
692 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
4 ms |
692 KB |
Output is correct |
10 |
Correct |
3 ms |
728 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
3 ms |
728 KB |
Output is correct |
13 |
Correct |
3 ms |
728 KB |
Output is correct |
14 |
Correct |
4 ms |
728 KB |
Output is correct |
15 |
Correct |
3 ms |
796 KB |
Output is correct |
16 |
Correct |
3 ms |
796 KB |
Output is correct |
17 |
Correct |
3 ms |
796 KB |
Output is correct |
18 |
Correct |
3 ms |
796 KB |
Output is correct |
19 |
Correct |
2 ms |
796 KB |
Output is correct |
20 |
Correct |
2 ms |
796 KB |
Output is correct |
21 |
Correct |
2 ms |
796 KB |
Output is correct |
22 |
Correct |
3 ms |
796 KB |
Output is correct |
23 |
Correct |
2 ms |
796 KB |
Output is correct |
24 |
Correct |
3 ms |
796 KB |
Output is correct |
25 |
Correct |
3 ms |
796 KB |
Output is correct |
26 |
Correct |
2 ms |
796 KB |
Output is correct |
27 |
Correct |
3 ms |
796 KB |
Output is correct |
28 |
Correct |
2 ms |
796 KB |
Output is correct |
29 |
Correct |
3 ms |
796 KB |
Output is correct |
30 |
Correct |
3 ms |
796 KB |
Output is correct |
31 |
Correct |
2 ms |
796 KB |
Output is correct |
32 |
Correct |
3 ms |
796 KB |
Output is correct |
33 |
Correct |
2 ms |
796 KB |
Output is correct |
34 |
Correct |
3 ms |
796 KB |
Output is correct |
35 |
Correct |
3 ms |
796 KB |
Output is correct |
36 |
Correct |
2 ms |
796 KB |
Output is correct |
37 |
Correct |
3 ms |
796 KB |
Output is correct |
38 |
Correct |
2 ms |
796 KB |
Output is correct |
39 |
Correct |
1 ms |
796 KB |
Output is correct |
40 |
Correct |
3 ms |
796 KB |
Output is correct |
41 |
Correct |
3 ms |
796 KB |
Output is correct |
42 |
Correct |
3 ms |
800 KB |
Output is correct |
43 |
Correct |
3 ms |
800 KB |
Output is correct |
44 |
Correct |
3 ms |
808 KB |
Output is correct |
45 |
Correct |
3 ms |
872 KB |
Output is correct |
46 |
Correct |
4 ms |
872 KB |
Output is correct |
47 |
Correct |
2 ms |
872 KB |
Output is correct |
48 |
Correct |
2 ms |
872 KB |
Output is correct |
49 |
Correct |
3 ms |
872 KB |
Output is correct |
50 |
Correct |
3 ms |
872 KB |
Output is correct |
51 |
Correct |
3 ms |
872 KB |
Output is correct |
52 |
Correct |
3 ms |
872 KB |
Output is correct |
53 |
Correct |
3 ms |
900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
692 KB |
Output is correct |
5 |
Correct |
2 ms |
692 KB |
Output is correct |
6 |
Correct |
2 ms |
692 KB |
Output is correct |
7 |
Correct |
3 ms |
692 KB |
Output is correct |
8 |
Correct |
2 ms |
692 KB |
Output is correct |
9 |
Correct |
4 ms |
692 KB |
Output is correct |
10 |
Correct |
3 ms |
728 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
3 ms |
728 KB |
Output is correct |
13 |
Correct |
3 ms |
728 KB |
Output is correct |
14 |
Correct |
4 ms |
728 KB |
Output is correct |
15 |
Correct |
3 ms |
796 KB |
Output is correct |
16 |
Correct |
3 ms |
796 KB |
Output is correct |
17 |
Correct |
3 ms |
796 KB |
Output is correct |
18 |
Correct |
3 ms |
796 KB |
Output is correct |
19 |
Correct |
2 ms |
796 KB |
Output is correct |
20 |
Correct |
2 ms |
796 KB |
Output is correct |
21 |
Correct |
2 ms |
796 KB |
Output is correct |
22 |
Correct |
3 ms |
796 KB |
Output is correct |
23 |
Correct |
2 ms |
796 KB |
Output is correct |
24 |
Correct |
3 ms |
796 KB |
Output is correct |
25 |
Correct |
3 ms |
796 KB |
Output is correct |
26 |
Correct |
2 ms |
796 KB |
Output is correct |
27 |
Correct |
3 ms |
796 KB |
Output is correct |
28 |
Correct |
2 ms |
796 KB |
Output is correct |
29 |
Correct |
3 ms |
796 KB |
Output is correct |
30 |
Correct |
3 ms |
796 KB |
Output is correct |
31 |
Correct |
2 ms |
796 KB |
Output is correct |
32 |
Correct |
3 ms |
796 KB |
Output is correct |
33 |
Correct |
2 ms |
796 KB |
Output is correct |
34 |
Correct |
3 ms |
796 KB |
Output is correct |
35 |
Correct |
3 ms |
796 KB |
Output is correct |
36 |
Correct |
2 ms |
796 KB |
Output is correct |
37 |
Correct |
3 ms |
796 KB |
Output is correct |
38 |
Correct |
2 ms |
796 KB |
Output is correct |
39 |
Correct |
1 ms |
796 KB |
Output is correct |
40 |
Correct |
3 ms |
796 KB |
Output is correct |
41 |
Correct |
3 ms |
796 KB |
Output is correct |
42 |
Correct |
3 ms |
800 KB |
Output is correct |
43 |
Correct |
3 ms |
800 KB |
Output is correct |
44 |
Correct |
3 ms |
808 KB |
Output is correct |
45 |
Correct |
3 ms |
872 KB |
Output is correct |
46 |
Correct |
4 ms |
872 KB |
Output is correct |
47 |
Correct |
2 ms |
872 KB |
Output is correct |
48 |
Correct |
2 ms |
872 KB |
Output is correct |
49 |
Correct |
3 ms |
872 KB |
Output is correct |
50 |
Correct |
3 ms |
872 KB |
Output is correct |
51 |
Correct |
3 ms |
872 KB |
Output is correct |
52 |
Correct |
3 ms |
872 KB |
Output is correct |
53 |
Correct |
3 ms |
900 KB |
Output is correct |
54 |
Correct |
3 ms |
900 KB |
Output is correct |
55 |
Correct |
47 ms |
10072 KB |
Output is correct |
56 |
Correct |
4 ms |
10072 KB |
Output is correct |
57 |
Correct |
32 ms |
13724 KB |
Output is correct |
58 |
Correct |
86 ms |
13724 KB |
Output is correct |
59 |
Correct |
743 ms |
54736 KB |
Output is correct |
60 |
Correct |
640 ms |
54988 KB |
Output is correct |
61 |
Correct |
697 ms |
55064 KB |
Output is correct |
62 |
Correct |
3 ms |
55064 KB |
Output is correct |
63 |
Correct |
641 ms |
55064 KB |
Output is correct |
64 |
Correct |
622 ms |
55064 KB |
Output is correct |
65 |
Correct |
539 ms |
55092 KB |
Output is correct |
66 |
Correct |
641 ms |
55196 KB |
Output is correct |
67 |
Correct |
511 ms |
55196 KB |
Output is correct |
68 |
Correct |
478 ms |
55196 KB |
Output is correct |
69 |
Correct |
547 ms |
55196 KB |
Output is correct |
70 |
Correct |
70 ms |
55196 KB |
Output is correct |
71 |
Correct |
68 ms |
55196 KB |
Output is correct |
72 |
Correct |
69 ms |
55196 KB |
Output is correct |
73 |
Correct |
79 ms |
55196 KB |
Output is correct |
74 |
Correct |
83 ms |
55196 KB |
Output is correct |
75 |
Correct |
97 ms |
55196 KB |
Output is correct |
76 |
Correct |
77 ms |
55196 KB |
Output is correct |
77 |
Correct |
98 ms |
55196 KB |
Output is correct |
78 |
Correct |
92 ms |
55196 KB |
Output is correct |
79 |
Correct |
79 ms |
55196 KB |
Output is correct |
80 |
Correct |
89 ms |
55196 KB |
Output is correct |
81 |
Correct |
73 ms |
55196 KB |
Output is correct |
82 |
Correct |
86 ms |
55196 KB |
Output is correct |
83 |
Correct |
61 ms |
55196 KB |
Output is correct |
84 |
Correct |
70 ms |
55196 KB |
Output is correct |
85 |
Correct |
75 ms |
55196 KB |
Output is correct |
86 |
Correct |
76 ms |
55196 KB |
Output is correct |
87 |
Correct |
74 ms |
55196 KB |
Output is correct |
88 |
Correct |
65 ms |
55196 KB |
Output is correct |
89 |
Correct |
85 ms |
55196 KB |
Output is correct |
90 |
Correct |
73 ms |
55196 KB |
Output is correct |