#include <bits/stdc++.h>
using namespace std;
char a[3005][3005];
int type[3005][3005];
int dp[3005][4];
int main(){
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
//cout.tie(NULL);
int r, c;
cin>>r>>c;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin>>a[i][j];
}
}
memset(type, 0, sizeof type);
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
if(a[i][j]=='G'){
if(a[i-1][j]=='R' && a[i+1][j]=='W') type[i][j]+=1;
if(a[i][j-1]=='R' && a[i][j+1]=='W') type[i][j]+=2;
}
}
}
int ans=0;
vector<int>v;
for(int i=2;i<=r+c;i++){
int x, y;
if(i<=c) x=1, y=i-1;
else x=i-c, y=c;
v.clear();
while(x<=r && y>=1){
v.push_back(type[x][y]);
//cout<<x<<" "<<y<<endl;
x++, y--;
}
int n=v.size();
dp[0][0]=dp[0][1]=dp[0][2]=0;
for(int i=0;i<n;i++){
dp[i+1][0]=max({dp[i][0], dp[i][1], dp[i][2]});
dp[i+1][1]=0;
dp[i+1][2]=0;
if(v[i]==1 || v[i]==3) dp[i+1][1]=max(dp[i][1], dp[i][0])+1;
if(v[i]==2 || v[i]==3) dp[i+1][2]=max(dp[i][2], dp[i][0])+1;
}
ans+=max({dp[n][0], dp[n][1], dp[n][2]});
//cout<<ans<<endl;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
35712 KB |
Output is correct |
2 |
Correct |
25 ms |
35712 KB |
Output is correct |
3 |
Correct |
24 ms |
35712 KB |
Output is correct |
4 |
Correct |
28 ms |
35712 KB |
Output is correct |
5 |
Correct |
24 ms |
35712 KB |
Output is correct |
6 |
Correct |
24 ms |
35712 KB |
Output is correct |
7 |
Correct |
28 ms |
35792 KB |
Output is correct |
8 |
Correct |
24 ms |
35712 KB |
Output is correct |
9 |
Correct |
24 ms |
35712 KB |
Output is correct |
10 |
Correct |
24 ms |
35712 KB |
Output is correct |
11 |
Correct |
23 ms |
35840 KB |
Output is correct |
12 |
Correct |
23 ms |
35712 KB |
Output is correct |
13 |
Correct |
23 ms |
35712 KB |
Output is correct |
14 |
Correct |
23 ms |
35712 KB |
Output is correct |
15 |
Correct |
23 ms |
35712 KB |
Output is correct |
16 |
Correct |
23 ms |
35712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
35712 KB |
Output is correct |
2 |
Correct |
25 ms |
35712 KB |
Output is correct |
3 |
Correct |
24 ms |
35712 KB |
Output is correct |
4 |
Correct |
28 ms |
35712 KB |
Output is correct |
5 |
Correct |
24 ms |
35712 KB |
Output is correct |
6 |
Correct |
24 ms |
35712 KB |
Output is correct |
7 |
Correct |
28 ms |
35792 KB |
Output is correct |
8 |
Correct |
24 ms |
35712 KB |
Output is correct |
9 |
Correct |
24 ms |
35712 KB |
Output is correct |
10 |
Correct |
24 ms |
35712 KB |
Output is correct |
11 |
Correct |
23 ms |
35840 KB |
Output is correct |
12 |
Correct |
23 ms |
35712 KB |
Output is correct |
13 |
Correct |
23 ms |
35712 KB |
Output is correct |
14 |
Correct |
23 ms |
35712 KB |
Output is correct |
15 |
Correct |
23 ms |
35712 KB |
Output is correct |
16 |
Correct |
23 ms |
35712 KB |
Output is correct |
17 |
Correct |
23 ms |
35712 KB |
Output is correct |
18 |
Correct |
24 ms |
35712 KB |
Output is correct |
19 |
Correct |
23 ms |
35712 KB |
Output is correct |
20 |
Correct |
25 ms |
35748 KB |
Output is correct |
21 |
Correct |
23 ms |
35712 KB |
Output is correct |
22 |
Correct |
24 ms |
35712 KB |
Output is correct |
23 |
Correct |
22 ms |
35712 KB |
Output is correct |
24 |
Correct |
24 ms |
35712 KB |
Output is correct |
25 |
Correct |
25 ms |
35712 KB |
Output is correct |
26 |
Correct |
23 ms |
35712 KB |
Output is correct |
27 |
Correct |
23 ms |
35712 KB |
Output is correct |
28 |
Correct |
23 ms |
35712 KB |
Output is correct |
29 |
Correct |
23 ms |
35712 KB |
Output is correct |
30 |
Correct |
23 ms |
35712 KB |
Output is correct |
31 |
Correct |
23 ms |
35712 KB |
Output is correct |
32 |
Correct |
26 ms |
35712 KB |
Output is correct |
33 |
Correct |
30 ms |
35712 KB |
Output is correct |
34 |
Correct |
24 ms |
35712 KB |
Output is correct |
35 |
Correct |
25 ms |
35712 KB |
Output is correct |
36 |
Correct |
23 ms |
35712 KB |
Output is correct |
37 |
Correct |
23 ms |
35712 KB |
Output is correct |
38 |
Correct |
23 ms |
35712 KB |
Output is correct |
39 |
Correct |
23 ms |
35712 KB |
Output is correct |
40 |
Correct |
23 ms |
35712 KB |
Output is correct |
41 |
Correct |
25 ms |
35712 KB |
Output is correct |
42 |
Correct |
26 ms |
35712 KB |
Output is correct |
43 |
Correct |
23 ms |
35712 KB |
Output is correct |
44 |
Correct |
26 ms |
35704 KB |
Output is correct |
45 |
Correct |
23 ms |
35712 KB |
Output is correct |
46 |
Correct |
23 ms |
35712 KB |
Output is correct |
47 |
Correct |
23 ms |
35712 KB |
Output is correct |
48 |
Correct |
26 ms |
35704 KB |
Output is correct |
49 |
Correct |
24 ms |
35712 KB |
Output is correct |
50 |
Correct |
23 ms |
35704 KB |
Output is correct |
51 |
Correct |
26 ms |
35704 KB |
Output is correct |
52 |
Correct |
23 ms |
35712 KB |
Output is correct |
53 |
Correct |
26 ms |
35696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
35712 KB |
Output is correct |
2 |
Correct |
25 ms |
35712 KB |
Output is correct |
3 |
Correct |
24 ms |
35712 KB |
Output is correct |
4 |
Correct |
28 ms |
35712 KB |
Output is correct |
5 |
Correct |
24 ms |
35712 KB |
Output is correct |
6 |
Correct |
24 ms |
35712 KB |
Output is correct |
7 |
Correct |
28 ms |
35792 KB |
Output is correct |
8 |
Correct |
24 ms |
35712 KB |
Output is correct |
9 |
Correct |
24 ms |
35712 KB |
Output is correct |
10 |
Correct |
24 ms |
35712 KB |
Output is correct |
11 |
Correct |
23 ms |
35840 KB |
Output is correct |
12 |
Correct |
23 ms |
35712 KB |
Output is correct |
13 |
Correct |
23 ms |
35712 KB |
Output is correct |
14 |
Correct |
23 ms |
35712 KB |
Output is correct |
15 |
Correct |
23 ms |
35712 KB |
Output is correct |
16 |
Correct |
23 ms |
35712 KB |
Output is correct |
17 |
Correct |
23 ms |
35712 KB |
Output is correct |
18 |
Correct |
24 ms |
35712 KB |
Output is correct |
19 |
Correct |
23 ms |
35712 KB |
Output is correct |
20 |
Correct |
25 ms |
35748 KB |
Output is correct |
21 |
Correct |
23 ms |
35712 KB |
Output is correct |
22 |
Correct |
24 ms |
35712 KB |
Output is correct |
23 |
Correct |
22 ms |
35712 KB |
Output is correct |
24 |
Correct |
24 ms |
35712 KB |
Output is correct |
25 |
Correct |
25 ms |
35712 KB |
Output is correct |
26 |
Correct |
23 ms |
35712 KB |
Output is correct |
27 |
Correct |
23 ms |
35712 KB |
Output is correct |
28 |
Correct |
23 ms |
35712 KB |
Output is correct |
29 |
Correct |
23 ms |
35712 KB |
Output is correct |
30 |
Correct |
23 ms |
35712 KB |
Output is correct |
31 |
Correct |
23 ms |
35712 KB |
Output is correct |
32 |
Correct |
26 ms |
35712 KB |
Output is correct |
33 |
Correct |
30 ms |
35712 KB |
Output is correct |
34 |
Correct |
24 ms |
35712 KB |
Output is correct |
35 |
Correct |
25 ms |
35712 KB |
Output is correct |
36 |
Correct |
23 ms |
35712 KB |
Output is correct |
37 |
Correct |
23 ms |
35712 KB |
Output is correct |
38 |
Correct |
23 ms |
35712 KB |
Output is correct |
39 |
Correct |
23 ms |
35712 KB |
Output is correct |
40 |
Correct |
23 ms |
35712 KB |
Output is correct |
41 |
Correct |
25 ms |
35712 KB |
Output is correct |
42 |
Correct |
26 ms |
35712 KB |
Output is correct |
43 |
Correct |
23 ms |
35712 KB |
Output is correct |
44 |
Correct |
26 ms |
35704 KB |
Output is correct |
45 |
Correct |
23 ms |
35712 KB |
Output is correct |
46 |
Correct |
23 ms |
35712 KB |
Output is correct |
47 |
Correct |
23 ms |
35712 KB |
Output is correct |
48 |
Correct |
26 ms |
35704 KB |
Output is correct |
49 |
Correct |
24 ms |
35712 KB |
Output is correct |
50 |
Correct |
23 ms |
35704 KB |
Output is correct |
51 |
Correct |
26 ms |
35704 KB |
Output is correct |
52 |
Correct |
23 ms |
35712 KB |
Output is correct |
53 |
Correct |
26 ms |
35696 KB |
Output is correct |
54 |
Correct |
26 ms |
35704 KB |
Output is correct |
55 |
Correct |
30 ms |
44536 KB |
Output is correct |
56 |
Correct |
28 ms |
35704 KB |
Output is correct |
57 |
Correct |
30 ms |
41600 KB |
Output is correct |
58 |
Correct |
116 ms |
39600 KB |
Output is correct |
59 |
Correct |
923 ms |
53396 KB |
Output is correct |
60 |
Correct |
935 ms |
53524 KB |
Output is correct |
61 |
Correct |
940 ms |
53496 KB |
Output is correct |
62 |
Correct |
29 ms |
35712 KB |
Output is correct |
63 |
Correct |
926 ms |
53220 KB |
Output is correct |
64 |
Correct |
871 ms |
53344 KB |
Output is correct |
65 |
Correct |
902 ms |
53372 KB |
Output is correct |
66 |
Correct |
876 ms |
53628 KB |
Output is correct |
67 |
Correct |
855 ms |
53496 KB |
Output is correct |
68 |
Correct |
878 ms |
53360 KB |
Output is correct |
69 |
Correct |
863 ms |
53496 KB |
Output is correct |
70 |
Correct |
110 ms |
39672 KB |
Output is correct |
71 |
Correct |
110 ms |
39544 KB |
Output is correct |
72 |
Correct |
110 ms |
39544 KB |
Output is correct |
73 |
Correct |
114 ms |
39632 KB |
Output is correct |
74 |
Correct |
114 ms |
39544 KB |
Output is correct |
75 |
Correct |
111 ms |
39544 KB |
Output is correct |
76 |
Correct |
109 ms |
39580 KB |
Output is correct |
77 |
Correct |
110 ms |
39672 KB |
Output is correct |
78 |
Correct |
115 ms |
39672 KB |
Output is correct |
79 |
Correct |
111 ms |
39572 KB |
Output is correct |
80 |
Correct |
111 ms |
39672 KB |
Output is correct |
81 |
Correct |
114 ms |
39660 KB |
Output is correct |
82 |
Correct |
113 ms |
39672 KB |
Output is correct |
83 |
Correct |
110 ms |
39672 KB |
Output is correct |
84 |
Correct |
110 ms |
39544 KB |
Output is correct |
85 |
Correct |
112 ms |
39544 KB |
Output is correct |
86 |
Correct |
126 ms |
39548 KB |
Output is correct |
87 |
Correct |
110 ms |
39544 KB |
Output is correct |
88 |
Correct |
110 ms |
39544 KB |
Output is correct |
89 |
Correct |
114 ms |
39672 KB |
Output is correct |
90 |
Correct |
114 ms |
39648 KB |
Output is correct |