#include <iostream>
#include <fstream>
using namespace std;
const int nmax=3005;
int dp[nmax][nmax][2];
string s[nmax];
int n,m,i,j,ans;
int main()
{
ios_base::sync_with_stdio(false);
//freopen("data.in","r",stdin);
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>s[i];
s[i]=" "+s[i]+" ";
}
for(i=1;i<=m+1;i++)
s[0]+=" ",s[n+1]+=" ";
for(i=1;i<=n;i++)
for(j=m;j>=1;j--)
{
dp[i][j][0]=max(dp[i-1][j+1][0],dp[i-1][j+1][1]);
dp[i][j][1]=max(dp[i-1][j+1][0],dp[i-1][j+1][1]);
if(s[i][j]=='G')
{
if(s[i-1][j]=='R'&&s[i+1][j]=='W') dp[i][j][0]=max(dp[i-1][j+1][0]+1,dp[i][j][0]);
if(s[i][j-1]=='R'&&s[i][j+1]=='W') dp[i][j][1]=max(dp[i-1][j+1][1]+1,dp[i][j][1]);
}
if(j==1||i==n) ans+=max(dp[i][j][0],dp[i][j][1]);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
640 KB |
Output is correct |
33 |
Correct |
3 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
512 KB |
Output is correct |
35 |
Correct |
3 ms |
512 KB |
Output is correct |
36 |
Correct |
3 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
3 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
512 KB |
Output is correct |
42 |
Correct |
3 ms |
512 KB |
Output is correct |
43 |
Correct |
3 ms |
512 KB |
Output is correct |
44 |
Correct |
2 ms |
512 KB |
Output is correct |
45 |
Correct |
2 ms |
512 KB |
Output is correct |
46 |
Correct |
2 ms |
512 KB |
Output is correct |
47 |
Correct |
2 ms |
512 KB |
Output is correct |
48 |
Correct |
3 ms |
512 KB |
Output is correct |
49 |
Correct |
2 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
3 ms |
512 KB |
Output is correct |
52 |
Correct |
2 ms |
512 KB |
Output is correct |
53 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
640 KB |
Output is correct |
33 |
Correct |
3 ms |
512 KB |
Output is correct |
34 |
Correct |
3 ms |
512 KB |
Output is correct |
35 |
Correct |
3 ms |
512 KB |
Output is correct |
36 |
Correct |
3 ms |
512 KB |
Output is correct |
37 |
Correct |
2 ms |
512 KB |
Output is correct |
38 |
Correct |
3 ms |
512 KB |
Output is correct |
39 |
Correct |
2 ms |
512 KB |
Output is correct |
40 |
Correct |
2 ms |
512 KB |
Output is correct |
41 |
Correct |
2 ms |
512 KB |
Output is correct |
42 |
Correct |
3 ms |
512 KB |
Output is correct |
43 |
Correct |
3 ms |
512 KB |
Output is correct |
44 |
Correct |
2 ms |
512 KB |
Output is correct |
45 |
Correct |
2 ms |
512 KB |
Output is correct |
46 |
Correct |
2 ms |
512 KB |
Output is correct |
47 |
Correct |
2 ms |
512 KB |
Output is correct |
48 |
Correct |
3 ms |
512 KB |
Output is correct |
49 |
Correct |
2 ms |
512 KB |
Output is correct |
50 |
Correct |
2 ms |
512 KB |
Output is correct |
51 |
Correct |
3 ms |
512 KB |
Output is correct |
52 |
Correct |
2 ms |
512 KB |
Output is correct |
53 |
Correct |
2 ms |
512 KB |
Output is correct |
54 |
Correct |
2 ms |
512 KB |
Output is correct |
55 |
Correct |
14 ms |
12544 KB |
Output is correct |
56 |
Correct |
3 ms |
640 KB |
Output is correct |
57 |
Correct |
10 ms |
8704 KB |
Output is correct |
58 |
Correct |
24 ms |
15224 KB |
Output is correct |
59 |
Correct |
199 ms |
91000 KB |
Output is correct |
60 |
Correct |
176 ms |
91000 KB |
Output is correct |
61 |
Correct |
195 ms |
90944 KB |
Output is correct |
62 |
Correct |
2 ms |
512 KB |
Output is correct |
63 |
Correct |
183 ms |
90488 KB |
Output is correct |
64 |
Correct |
108 ms |
91000 KB |
Output is correct |
65 |
Correct |
121 ms |
91088 KB |
Output is correct |
66 |
Correct |
116 ms |
91200 KB |
Output is correct |
67 |
Correct |
114 ms |
91128 KB |
Output is correct |
68 |
Correct |
112 ms |
91084 KB |
Output is correct |
69 |
Correct |
121 ms |
91128 KB |
Output is correct |
70 |
Correct |
22 ms |
15480 KB |
Output is correct |
71 |
Correct |
20 ms |
15204 KB |
Output is correct |
72 |
Correct |
22 ms |
15204 KB |
Output is correct |
73 |
Correct |
24 ms |
15224 KB |
Output is correct |
74 |
Correct |
18 ms |
15232 KB |
Output is correct |
75 |
Correct |
19 ms |
15224 KB |
Output is correct |
76 |
Correct |
21 ms |
15232 KB |
Output is correct |
77 |
Correct |
19 ms |
15232 KB |
Output is correct |
78 |
Correct |
18 ms |
15232 KB |
Output is correct |
79 |
Correct |
19 ms |
15232 KB |
Output is correct |
80 |
Correct |
17 ms |
15232 KB |
Output is correct |
81 |
Correct |
21 ms |
15232 KB |
Output is correct |
82 |
Correct |
22 ms |
15232 KB |
Output is correct |
83 |
Correct |
19 ms |
15224 KB |
Output is correct |
84 |
Correct |
25 ms |
15224 KB |
Output is correct |
85 |
Correct |
19 ms |
15232 KB |
Output is correct |
86 |
Correct |
20 ms |
15224 KB |
Output is correct |
87 |
Correct |
24 ms |
15232 KB |
Output is correct |
88 |
Correct |
22 ms |
15272 KB |
Output is correct |
89 |
Correct |
19 ms |
15232 KB |
Output is correct |
90 |
Correct |
25 ms |
15232 KB |
Output is correct |