#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int n,m;
ii arr[3000][3000];
char arr1[3000][3000];
int dp[3001][3][3];
int cal(int i,int j,int k,int l)
{
if(dp[i][k][l]!=-1)
return(dp[i][k][l]);
dp[i][k][l]=0;
if(i==n||j==m)
return(0);
int ans=0;
ans=cal(i+1,j+1,0,k);
if(arr[i][j].F==1)
ans=max(ans,1+cal(i+1,j+1,1,k));
if(arr[i][j].S==1&&k!=1&&l!=1)
ans=max(ans,1+cal(i+1,j+1,2,k));
dp[i][k][l]=ans;
return(dp[i][k][l]);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=n-1;i>=0;--i)
for(int j=0;j<m;++j)
cin>>arr1[i][j];
for(int i=0;i<n;++i)
{
for(int j=0;j<m;++j)
{
arr[i][j]=mp(0,0);
if(i>1&&arr1[i][j]=='R'&&arr1[i-1][j]=='G'&&arr1[i-2][j]=='W')
arr[i][j].S=1;
if(j+2<m&&arr1[i][j]=='R'&&arr1[i][j+1]=='G'&&arr1[i][j+2]=='W')
arr[i][j].F=1;
}
}
int ans=0;
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
for(int k=0;k<3;++k)
for(int l=0;l<3;++l)
dp[j][k][l]=-1;
ans+=cal(i,0,0,0);
}
for(int j=1;j<m;++j)
{
for(int i=0;i<n;++i)
for(int k=0;k<3;++k)
for(int l=0;l<3;++l)
dp[i][k][l]=-1;
ans+=cal(0,j,0,0);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
1 ms |
384 KB |
Output is correct |
42 |
Correct |
0 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
0 ms |
384 KB |
Output is correct |
45 |
Correct |
1 ms |
384 KB |
Output is correct |
46 |
Correct |
0 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
0 ms |
384 KB |
Output is correct |
49 |
Correct |
0 ms |
384 KB |
Output is correct |
50 |
Correct |
0 ms |
384 KB |
Output is correct |
51 |
Correct |
0 ms |
384 KB |
Output is correct |
52 |
Correct |
0 ms |
384 KB |
Output is correct |
53 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
0 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
1 ms |
384 KB |
Output is correct |
42 |
Correct |
0 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
0 ms |
384 KB |
Output is correct |
45 |
Correct |
1 ms |
384 KB |
Output is correct |
46 |
Correct |
0 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
0 ms |
384 KB |
Output is correct |
49 |
Correct |
0 ms |
384 KB |
Output is correct |
50 |
Correct |
0 ms |
384 KB |
Output is correct |
51 |
Correct |
0 ms |
384 KB |
Output is correct |
52 |
Correct |
0 ms |
384 KB |
Output is correct |
53 |
Correct |
0 ms |
384 KB |
Output is correct |
54 |
Correct |
0 ms |
384 KB |
Output is correct |
55 |
Correct |
43 ms |
21376 KB |
Output is correct |
56 |
Correct |
1 ms |
512 KB |
Output is correct |
57 |
Correct |
21 ms |
14336 KB |
Output is correct |
58 |
Correct |
53 ms |
15488 KB |
Output is correct |
59 |
Correct |
514 ms |
84344 KB |
Output is correct |
60 |
Correct |
499 ms |
84344 KB |
Output is correct |
61 |
Correct |
493 ms |
88696 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
479 ms |
88560 KB |
Output is correct |
64 |
Correct |
814 ms |
88824 KB |
Output is correct |
65 |
Correct |
830 ms |
88952 KB |
Output is correct |
66 |
Correct |
841 ms |
88836 KB |
Output is correct |
67 |
Correct |
521 ms |
88824 KB |
Output is correct |
68 |
Correct |
513 ms |
88760 KB |
Output is correct |
69 |
Correct |
499 ms |
88824 KB |
Output is correct |
70 |
Correct |
78 ms |
16128 KB |
Output is correct |
71 |
Correct |
82 ms |
16128 KB |
Output is correct |
72 |
Correct |
84 ms |
16120 KB |
Output is correct |
73 |
Correct |
91 ms |
16256 KB |
Output is correct |
74 |
Correct |
81 ms |
16128 KB |
Output is correct |
75 |
Correct |
81 ms |
16120 KB |
Output is correct |
76 |
Correct |
85 ms |
16128 KB |
Output is correct |
77 |
Correct |
77 ms |
16128 KB |
Output is correct |
78 |
Correct |
83 ms |
16252 KB |
Output is correct |
79 |
Correct |
84 ms |
16120 KB |
Output is correct |
80 |
Correct |
88 ms |
16248 KB |
Output is correct |
81 |
Correct |
81 ms |
16128 KB |
Output is correct |
82 |
Correct |
80 ms |
16128 KB |
Output is correct |
83 |
Correct |
81 ms |
16120 KB |
Output is correct |
84 |
Correct |
83 ms |
16128 KB |
Output is correct |
85 |
Correct |
84 ms |
16120 KB |
Output is correct |
86 |
Correct |
82 ms |
16128 KB |
Output is correct |
87 |
Correct |
78 ms |
16168 KB |
Output is correct |
88 |
Correct |
84 ms |
16128 KB |
Output is correct |
89 |
Correct |
92 ms |
16248 KB |
Output is correct |
90 |
Correct |
84 ms |
16120 KB |
Output is correct |