#include<bits/stdc++.h>
#define maxn 500009
using namespace std;
string s[3009];
bool A[3009][3009];
bool B[3009][3009];
int ans;
int dp[6009][3];
main(){
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> s[i];
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(j + 2 < m && s[i][j] == 'R'
&& s[i][j+1] == 'G'
&& s[i][j+2] == 'W')
A[i][j] = 1;
if(i + 2 < n && s[i][j] == 'R'
&& s[i+1][j] == 'G'
&& s[i+2][j] == 'W')
B[i][j] = 1;
}
}
for(int ipj = 0; ipj < n+m-1; ipj++){
vector<int> a, b;
for(int i = 0; i < 3; i++)
a.push_back(0), b.push_back(0);
for(int i = n - 1; i >= 0; i--){
int j = ipj - i;
if(j < 0 || j >= m) continue;
a.push_back(A[i][j]);
b.push_back(B[i][j]);
}
int N = a.size();
for(int i = 3; i < N; i++){
dp[i][0] = max(dp[i-1][0], max(dp[i-1][1], dp[i-1][2]));
if(a[i]) dp[i][1] = dp[i][0] + 1;
else dp[i][1] = 0;
if(b[i]) dp[i][2] = max(dp[i-1][2] + 1,
max(dp[i-2][0],dp[i-2][2]) + 1);
else dp[i][2] = 0;
}
ans += max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2]) );
}
cout << ans << endl;
}
Compilation message
dango_maker.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
588 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
3 ms |
756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
588 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
3 ms |
756 KB |
Output is correct |
17 |
Correct |
3 ms |
756 KB |
Output is correct |
18 |
Correct |
2 ms |
756 KB |
Output is correct |
19 |
Correct |
3 ms |
820 KB |
Output is correct |
20 |
Correct |
3 ms |
828 KB |
Output is correct |
21 |
Correct |
4 ms |
828 KB |
Output is correct |
22 |
Correct |
4 ms |
828 KB |
Output is correct |
23 |
Correct |
3 ms |
836 KB |
Output is correct |
24 |
Correct |
3 ms |
836 KB |
Output is correct |
25 |
Correct |
3 ms |
836 KB |
Output is correct |
26 |
Correct |
4 ms |
836 KB |
Output is correct |
27 |
Correct |
4 ms |
852 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
860 KB |
Output is correct |
32 |
Correct |
3 ms |
860 KB |
Output is correct |
33 |
Correct |
3 ms |
876 KB |
Output is correct |
34 |
Correct |
3 ms |
876 KB |
Output is correct |
35 |
Correct |
4 ms |
1004 KB |
Output is correct |
36 |
Correct |
3 ms |
1004 KB |
Output is correct |
37 |
Correct |
4 ms |
1004 KB |
Output is correct |
38 |
Correct |
4 ms |
1004 KB |
Output is correct |
39 |
Correct |
3 ms |
1004 KB |
Output is correct |
40 |
Correct |
3 ms |
1032 KB |
Output is correct |
41 |
Correct |
3 ms |
1032 KB |
Output is correct |
42 |
Correct |
3 ms |
1032 KB |
Output is correct |
43 |
Correct |
3 ms |
1100 KB |
Output is correct |
44 |
Correct |
4 ms |
1100 KB |
Output is correct |
45 |
Correct |
3 ms |
1100 KB |
Output is correct |
46 |
Correct |
2 ms |
1100 KB |
Output is correct |
47 |
Correct |
3 ms |
1100 KB |
Output is correct |
48 |
Correct |
3 ms |
1100 KB |
Output is correct |
49 |
Correct |
2 ms |
1100 KB |
Output is correct |
50 |
Correct |
2 ms |
1100 KB |
Output is correct |
51 |
Correct |
3 ms |
1100 KB |
Output is correct |
52 |
Correct |
3 ms |
1100 KB |
Output is correct |
53 |
Correct |
3 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
588 KB |
Output is correct |
5 |
Correct |
3 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
3 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
716 KB |
Output is correct |
14 |
Correct |
3 ms |
716 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
3 ms |
756 KB |
Output is correct |
17 |
Correct |
3 ms |
756 KB |
Output is correct |
18 |
Correct |
2 ms |
756 KB |
Output is correct |
19 |
Correct |
3 ms |
820 KB |
Output is correct |
20 |
Correct |
3 ms |
828 KB |
Output is correct |
21 |
Correct |
4 ms |
828 KB |
Output is correct |
22 |
Correct |
4 ms |
828 KB |
Output is correct |
23 |
Correct |
3 ms |
836 KB |
Output is correct |
24 |
Correct |
3 ms |
836 KB |
Output is correct |
25 |
Correct |
3 ms |
836 KB |
Output is correct |
26 |
Correct |
4 ms |
836 KB |
Output is correct |
27 |
Correct |
4 ms |
852 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
2 ms |
860 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
860 KB |
Output is correct |
32 |
Correct |
3 ms |
860 KB |
Output is correct |
33 |
Correct |
3 ms |
876 KB |
Output is correct |
34 |
Correct |
3 ms |
876 KB |
Output is correct |
35 |
Correct |
4 ms |
1004 KB |
Output is correct |
36 |
Correct |
3 ms |
1004 KB |
Output is correct |
37 |
Correct |
4 ms |
1004 KB |
Output is correct |
38 |
Correct |
4 ms |
1004 KB |
Output is correct |
39 |
Correct |
3 ms |
1004 KB |
Output is correct |
40 |
Correct |
3 ms |
1032 KB |
Output is correct |
41 |
Correct |
3 ms |
1032 KB |
Output is correct |
42 |
Correct |
3 ms |
1032 KB |
Output is correct |
43 |
Correct |
3 ms |
1100 KB |
Output is correct |
44 |
Correct |
4 ms |
1100 KB |
Output is correct |
45 |
Correct |
3 ms |
1100 KB |
Output is correct |
46 |
Correct |
2 ms |
1100 KB |
Output is correct |
47 |
Correct |
3 ms |
1100 KB |
Output is correct |
48 |
Correct |
3 ms |
1100 KB |
Output is correct |
49 |
Correct |
2 ms |
1100 KB |
Output is correct |
50 |
Correct |
2 ms |
1100 KB |
Output is correct |
51 |
Correct |
3 ms |
1100 KB |
Output is correct |
52 |
Correct |
3 ms |
1100 KB |
Output is correct |
53 |
Correct |
3 ms |
1100 KB |
Output is correct |
54 |
Correct |
4 ms |
1100 KB |
Output is correct |
55 |
Correct |
17 ms |
1452 KB |
Output is correct |
56 |
Correct |
6 ms |
1452 KB |
Output is correct |
57 |
Correct |
16 ms |
9428 KB |
Output is correct |
58 |
Correct |
122 ms |
9848 KB |
Output is correct |
59 |
Correct |
631 ms |
40028 KB |
Output is correct |
60 |
Correct |
647 ms |
48824 KB |
Output is correct |
61 |
Correct |
829 ms |
57648 KB |
Output is correct |
62 |
Correct |
6 ms |
57648 KB |
Output is correct |
63 |
Correct |
697 ms |
66272 KB |
Output is correct |
64 |
Correct |
763 ms |
74988 KB |
Output is correct |
65 |
Correct |
621 ms |
83868 KB |
Output is correct |
66 |
Correct |
563 ms |
92628 KB |
Output is correct |
67 |
Correct |
586 ms |
92628 KB |
Output is correct |
68 |
Correct |
578 ms |
99804 KB |
Output is correct |
69 |
Correct |
640 ms |
114752 KB |
Output is correct |
70 |
Correct |
63 ms |
114752 KB |
Output is correct |
71 |
Correct |
71 ms |
114752 KB |
Output is correct |
72 |
Correct |
73 ms |
114752 KB |
Output is correct |
73 |
Correct |
68 ms |
114752 KB |
Output is correct |
74 |
Correct |
67 ms |
114752 KB |
Output is correct |
75 |
Correct |
75 ms |
114752 KB |
Output is correct |
76 |
Correct |
67 ms |
114752 KB |
Output is correct |
77 |
Correct |
61 ms |
114752 KB |
Output is correct |
78 |
Correct |
70 ms |
114752 KB |
Output is correct |
79 |
Correct |
74 ms |
114752 KB |
Output is correct |
80 |
Correct |
70 ms |
114752 KB |
Output is correct |
81 |
Correct |
65 ms |
114752 KB |
Output is correct |
82 |
Correct |
66 ms |
114752 KB |
Output is correct |
83 |
Correct |
78 ms |
114752 KB |
Output is correct |
84 |
Correct |
84 ms |
114752 KB |
Output is correct |
85 |
Correct |
65 ms |
114752 KB |
Output is correct |
86 |
Correct |
71 ms |
114752 KB |
Output is correct |
87 |
Correct |
76 ms |
115404 KB |
Output is correct |
88 |
Correct |
99 ms |
116512 KB |
Output is correct |
89 |
Correct |
96 ms |
117380 KB |
Output is correct |
90 |
Correct |
72 ms |
118568 KB |
Output is correct |