#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N=3005;
int n,m,dp[N][3];
bool can[N][N][3];
char a[N][N];
vector<pii>vec[N*2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
vec[i+j].push_back(mp(i,j));
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i-1][j]=='R'&&a[i][j]=='G'&&a[i+1][j]=='W') can[i][j][1]=true;
if(a[i][j-1]=='R'&&a[i][j]=='G'&&a[i][j+1]=='W') can[i][j][2]=true;
}
}
int res=0;
for(int s=2;s<=n+m;s++)
{
memset(dp,0,sizeof dp);
int sz=vec[s].size();
for(int i=1;i<=sz;i++)
{
int x=vec[s][i-1].fi;
int y=vec[s][i-1].se;
dp[i][0]=max({dp[i-1][0],dp[i-1][1],dp[i-1][2]});
for(int j=1;j<=2;j++) if(can[x][y][j]) dp[i][j]=max(dp[i-1][0],dp[i-1][j])+1;
}
res=res+max({dp[sz][0],dp[sz][1],dp[sz][2]});
}
cout<<res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
640 KB |
Output is correct |
22 |
Correct |
1 ms |
640 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
640 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
1 ms |
640 KB |
Output is correct |
34 |
Correct |
1 ms |
640 KB |
Output is correct |
35 |
Correct |
1 ms |
640 KB |
Output is correct |
36 |
Correct |
1 ms |
640 KB |
Output is correct |
37 |
Correct |
1 ms |
640 KB |
Output is correct |
38 |
Correct |
1 ms |
640 KB |
Output is correct |
39 |
Correct |
1 ms |
640 KB |
Output is correct |
40 |
Correct |
1 ms |
640 KB |
Output is correct |
41 |
Correct |
1 ms |
640 KB |
Output is correct |
42 |
Correct |
1 ms |
640 KB |
Output is correct |
43 |
Correct |
1 ms |
640 KB |
Output is correct |
44 |
Correct |
1 ms |
640 KB |
Output is correct |
45 |
Correct |
1 ms |
640 KB |
Output is correct |
46 |
Correct |
1 ms |
640 KB |
Output is correct |
47 |
Correct |
1 ms |
640 KB |
Output is correct |
48 |
Correct |
1 ms |
640 KB |
Output is correct |
49 |
Correct |
1 ms |
640 KB |
Output is correct |
50 |
Correct |
1 ms |
640 KB |
Output is correct |
51 |
Correct |
1 ms |
640 KB |
Output is correct |
52 |
Correct |
1 ms |
640 KB |
Output is correct |
53 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
640 KB |
Output is correct |
22 |
Correct |
1 ms |
640 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
640 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
1 ms |
640 KB |
Output is correct |
34 |
Correct |
1 ms |
640 KB |
Output is correct |
35 |
Correct |
1 ms |
640 KB |
Output is correct |
36 |
Correct |
1 ms |
640 KB |
Output is correct |
37 |
Correct |
1 ms |
640 KB |
Output is correct |
38 |
Correct |
1 ms |
640 KB |
Output is correct |
39 |
Correct |
1 ms |
640 KB |
Output is correct |
40 |
Correct |
1 ms |
640 KB |
Output is correct |
41 |
Correct |
1 ms |
640 KB |
Output is correct |
42 |
Correct |
1 ms |
640 KB |
Output is correct |
43 |
Correct |
1 ms |
640 KB |
Output is correct |
44 |
Correct |
1 ms |
640 KB |
Output is correct |
45 |
Correct |
1 ms |
640 KB |
Output is correct |
46 |
Correct |
1 ms |
640 KB |
Output is correct |
47 |
Correct |
1 ms |
640 KB |
Output is correct |
48 |
Correct |
1 ms |
640 KB |
Output is correct |
49 |
Correct |
1 ms |
640 KB |
Output is correct |
50 |
Correct |
1 ms |
640 KB |
Output is correct |
51 |
Correct |
1 ms |
640 KB |
Output is correct |
52 |
Correct |
1 ms |
640 KB |
Output is correct |
53 |
Correct |
1 ms |
640 KB |
Output is correct |
54 |
Correct |
4 ms |
640 KB |
Output is correct |
55 |
Correct |
10 ms |
9856 KB |
Output is correct |
56 |
Correct |
6 ms |
896 KB |
Output is correct |
57 |
Correct |
11 ms |
13560 KB |
Output is correct |
58 |
Correct |
54 ms |
21880 KB |
Output is correct |
59 |
Correct |
563 ms |
137208 KB |
Output is correct |
60 |
Correct |
562 ms |
137336 KB |
Output is correct |
61 |
Correct |
569 ms |
137208 KB |
Output is correct |
62 |
Correct |
6 ms |
768 KB |
Output is correct |
63 |
Correct |
545 ms |
133828 KB |
Output is correct |
64 |
Correct |
487 ms |
137232 KB |
Output is correct |
65 |
Correct |
490 ms |
137208 KB |
Output is correct |
66 |
Correct |
480 ms |
137336 KB |
Output is correct |
67 |
Correct |
462 ms |
123512 KB |
Output is correct |
68 |
Correct |
467 ms |
123640 KB |
Output is correct |
69 |
Correct |
487 ms |
128632 KB |
Output is correct |
70 |
Correct |
49 ms |
22008 KB |
Output is correct |
71 |
Correct |
45 ms |
22008 KB |
Output is correct |
72 |
Correct |
49 ms |
22016 KB |
Output is correct |
73 |
Correct |
46 ms |
22012 KB |
Output is correct |
74 |
Correct |
48 ms |
22008 KB |
Output is correct |
75 |
Correct |
51 ms |
22008 KB |
Output is correct |
76 |
Correct |
45 ms |
22008 KB |
Output is correct |
77 |
Correct |
46 ms |
22008 KB |
Output is correct |
78 |
Correct |
47 ms |
22008 KB |
Output is correct |
79 |
Correct |
46 ms |
22008 KB |
Output is correct |
80 |
Correct |
47 ms |
22008 KB |
Output is correct |
81 |
Correct |
47 ms |
22008 KB |
Output is correct |
82 |
Correct |
45 ms |
22136 KB |
Output is correct |
83 |
Correct |
47 ms |
22008 KB |
Output is correct |
84 |
Correct |
46 ms |
21972 KB |
Output is correct |
85 |
Correct |
45 ms |
22008 KB |
Output is correct |
86 |
Correct |
45 ms |
22008 KB |
Output is correct |
87 |
Correct |
46 ms |
22008 KB |
Output is correct |
88 |
Correct |
45 ms |
22008 KB |
Output is correct |
89 |
Correct |
47 ms |
22008 KB |
Output is correct |
90 |
Correct |
45 ms |
22008 KB |
Output is correct |