#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll INF=1e9,LINF=1e18,MOD=1e9+7; const ll MAXN=4e3+1,MAXS=2*3e3+1;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush;
#define pb push_back
#define PRINTvec(x) { cerr<<#x<<"-"; for(auto i_:x) cerr<<i_<<" "; cerr<<endl; }
int dp[MAXN][2][2];
int start[MAXS][MAXN][2];
void Solve(){
int N,M; cin>>N>>M;
vector<vector<char>> a(MAXN+3,vector<char>(MAXN+3,'@'));
for(int i=1;i<=N;i++){
string s; cin>>s;
for(int j=1;j<=M;j++){
a[i][j]=s[j-1];
}
}
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
if(a[i][j]=='R' && a[i+1][j]=='G' && a[i+2][j]=='W') start[i+j][i][1]=true;
if(a[i][j]=='R' && a[i][j+1]=='G' && a[i][j+2]=='W') start[i+j][i][0]=true;
}
}
function<void(int&,int)> Smax=[&](int& a,int b){
a=max(a,b);
};
function<void()> Build=[&](){
for(int i=1;i<=N;i++){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
dp[i][j][k]=-INF;
}
}
}
};
int res=0;
for(int z=2;z<=N+M;z++){
Build();
dp[0][0][0]=0;
for(int i=1;i<=N;i++){
for(int x=0;x<2;x++){
for(int y=0;y<2;y++){
Smax(dp[i][0][x],dp[i-1][x][y]);
if(start[z][i][0] && x==0 && y==0) Smax(dp[i][0][x],dp[i-1][x][y]+1);
if(start[z][i][1]) Smax(dp[i][1][x],dp[i-1][x][y]+1);
}
}
}
int tmp=0;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
tmp=max(tmp,dp[N][i][j]);
}
}
res+=tmp;
}
cout<<res<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t; t=1;
//cin>>t;
while(t--){
Solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
16084 KB |
Output is correct |
2 |
Correct |
7 ms |
16084 KB |
Output is correct |
3 |
Correct |
7 ms |
16144 KB |
Output is correct |
4 |
Correct |
8 ms |
16084 KB |
Output is correct |
5 |
Correct |
9 ms |
16084 KB |
Output is correct |
6 |
Correct |
7 ms |
16072 KB |
Output is correct |
7 |
Correct |
7 ms |
16084 KB |
Output is correct |
8 |
Correct |
7 ms |
16064 KB |
Output is correct |
9 |
Correct |
7 ms |
16072 KB |
Output is correct |
10 |
Correct |
7 ms |
16084 KB |
Output is correct |
11 |
Correct |
7 ms |
16084 KB |
Output is correct |
12 |
Correct |
8 ms |
16084 KB |
Output is correct |
13 |
Correct |
7 ms |
16084 KB |
Output is correct |
14 |
Correct |
7 ms |
16060 KB |
Output is correct |
15 |
Correct |
7 ms |
16116 KB |
Output is correct |
16 |
Correct |
7 ms |
16084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
16084 KB |
Output is correct |
2 |
Correct |
7 ms |
16084 KB |
Output is correct |
3 |
Correct |
7 ms |
16144 KB |
Output is correct |
4 |
Correct |
8 ms |
16084 KB |
Output is correct |
5 |
Correct |
9 ms |
16084 KB |
Output is correct |
6 |
Correct |
7 ms |
16072 KB |
Output is correct |
7 |
Correct |
7 ms |
16084 KB |
Output is correct |
8 |
Correct |
7 ms |
16064 KB |
Output is correct |
9 |
Correct |
7 ms |
16072 KB |
Output is correct |
10 |
Correct |
7 ms |
16084 KB |
Output is correct |
11 |
Correct |
7 ms |
16084 KB |
Output is correct |
12 |
Correct |
8 ms |
16084 KB |
Output is correct |
13 |
Correct |
7 ms |
16084 KB |
Output is correct |
14 |
Correct |
7 ms |
16060 KB |
Output is correct |
15 |
Correct |
7 ms |
16116 KB |
Output is correct |
16 |
Correct |
7 ms |
16084 KB |
Output is correct |
17 |
Correct |
8 ms |
16132 KB |
Output is correct |
18 |
Correct |
7 ms |
16084 KB |
Output is correct |
19 |
Correct |
7 ms |
16084 KB |
Output is correct |
20 |
Correct |
7 ms |
16084 KB |
Output is correct |
21 |
Correct |
7 ms |
16104 KB |
Output is correct |
22 |
Correct |
7 ms |
16212 KB |
Output is correct |
23 |
Correct |
7 ms |
16064 KB |
Output is correct |
24 |
Correct |
8 ms |
16084 KB |
Output is correct |
25 |
Correct |
8 ms |
16084 KB |
Output is correct |
26 |
Correct |
8 ms |
16168 KB |
Output is correct |
27 |
Correct |
8 ms |
16084 KB |
Output is correct |
28 |
Correct |
7 ms |
16084 KB |
Output is correct |
29 |
Correct |
8 ms |
16076 KB |
Output is correct |
30 |
Correct |
8 ms |
16212 KB |
Output is correct |
31 |
Correct |
7 ms |
16212 KB |
Output is correct |
32 |
Correct |
8 ms |
16084 KB |
Output is correct |
33 |
Correct |
7 ms |
16084 KB |
Output is correct |
34 |
Correct |
7 ms |
16084 KB |
Output is correct |
35 |
Correct |
7 ms |
16164 KB |
Output is correct |
36 |
Correct |
8 ms |
16084 KB |
Output is correct |
37 |
Correct |
7 ms |
16084 KB |
Output is correct |
38 |
Correct |
7 ms |
16072 KB |
Output is correct |
39 |
Correct |
7 ms |
16084 KB |
Output is correct |
40 |
Correct |
7 ms |
16084 KB |
Output is correct |
41 |
Correct |
9 ms |
16072 KB |
Output is correct |
42 |
Correct |
7 ms |
16064 KB |
Output is correct |
43 |
Correct |
7 ms |
16084 KB |
Output is correct |
44 |
Correct |
7 ms |
16084 KB |
Output is correct |
45 |
Correct |
7 ms |
16084 KB |
Output is correct |
46 |
Correct |
7 ms |
16072 KB |
Output is correct |
47 |
Correct |
7 ms |
16084 KB |
Output is correct |
48 |
Correct |
7 ms |
16084 KB |
Output is correct |
49 |
Correct |
7 ms |
16084 KB |
Output is correct |
50 |
Correct |
7 ms |
16084 KB |
Output is correct |
51 |
Correct |
7 ms |
16084 KB |
Output is correct |
52 |
Correct |
7 ms |
16084 KB |
Output is correct |
53 |
Correct |
7 ms |
16160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
16084 KB |
Output is correct |
2 |
Correct |
7 ms |
16084 KB |
Output is correct |
3 |
Correct |
7 ms |
16144 KB |
Output is correct |
4 |
Correct |
8 ms |
16084 KB |
Output is correct |
5 |
Correct |
9 ms |
16084 KB |
Output is correct |
6 |
Correct |
7 ms |
16072 KB |
Output is correct |
7 |
Correct |
7 ms |
16084 KB |
Output is correct |
8 |
Correct |
7 ms |
16064 KB |
Output is correct |
9 |
Correct |
7 ms |
16072 KB |
Output is correct |
10 |
Correct |
7 ms |
16084 KB |
Output is correct |
11 |
Correct |
7 ms |
16084 KB |
Output is correct |
12 |
Correct |
8 ms |
16084 KB |
Output is correct |
13 |
Correct |
7 ms |
16084 KB |
Output is correct |
14 |
Correct |
7 ms |
16060 KB |
Output is correct |
15 |
Correct |
7 ms |
16116 KB |
Output is correct |
16 |
Correct |
7 ms |
16084 KB |
Output is correct |
17 |
Correct |
8 ms |
16132 KB |
Output is correct |
18 |
Correct |
7 ms |
16084 KB |
Output is correct |
19 |
Correct |
7 ms |
16084 KB |
Output is correct |
20 |
Correct |
7 ms |
16084 KB |
Output is correct |
21 |
Correct |
7 ms |
16104 KB |
Output is correct |
22 |
Correct |
7 ms |
16212 KB |
Output is correct |
23 |
Correct |
7 ms |
16064 KB |
Output is correct |
24 |
Correct |
8 ms |
16084 KB |
Output is correct |
25 |
Correct |
8 ms |
16084 KB |
Output is correct |
26 |
Correct |
8 ms |
16168 KB |
Output is correct |
27 |
Correct |
8 ms |
16084 KB |
Output is correct |
28 |
Correct |
7 ms |
16084 KB |
Output is correct |
29 |
Correct |
8 ms |
16076 KB |
Output is correct |
30 |
Correct |
8 ms |
16212 KB |
Output is correct |
31 |
Correct |
7 ms |
16212 KB |
Output is correct |
32 |
Correct |
8 ms |
16084 KB |
Output is correct |
33 |
Correct |
7 ms |
16084 KB |
Output is correct |
34 |
Correct |
7 ms |
16084 KB |
Output is correct |
35 |
Correct |
7 ms |
16164 KB |
Output is correct |
36 |
Correct |
8 ms |
16084 KB |
Output is correct |
37 |
Correct |
7 ms |
16084 KB |
Output is correct |
38 |
Correct |
7 ms |
16072 KB |
Output is correct |
39 |
Correct |
7 ms |
16084 KB |
Output is correct |
40 |
Correct |
7 ms |
16084 KB |
Output is correct |
41 |
Correct |
9 ms |
16072 KB |
Output is correct |
42 |
Correct |
7 ms |
16064 KB |
Output is correct |
43 |
Correct |
7 ms |
16084 KB |
Output is correct |
44 |
Correct |
7 ms |
16084 KB |
Output is correct |
45 |
Correct |
7 ms |
16084 KB |
Output is correct |
46 |
Correct |
7 ms |
16072 KB |
Output is correct |
47 |
Correct |
7 ms |
16084 KB |
Output is correct |
48 |
Correct |
7 ms |
16084 KB |
Output is correct |
49 |
Correct |
7 ms |
16084 KB |
Output is correct |
50 |
Correct |
7 ms |
16084 KB |
Output is correct |
51 |
Correct |
7 ms |
16084 KB |
Output is correct |
52 |
Correct |
7 ms |
16084 KB |
Output is correct |
53 |
Correct |
7 ms |
16160 KB |
Output is correct |
54 |
Correct |
10 ms |
16728 KB |
Output is correct |
55 |
Correct |
175 ms |
16720 KB |
Output is correct |
56 |
Correct |
11 ms |
23764 KB |
Output is correct |
57 |
Correct |
85 ms |
22608 KB |
Output is correct |
58 |
Correct |
61 ms |
31688 KB |
Output is correct |
59 |
Correct |
461 ms |
109516 KB |
Output is correct |
60 |
Correct |
458 ms |
109388 KB |
Output is correct |
61 |
Correct |
466 ms |
109516 KB |
Output is correct |
62 |
Correct |
9 ms |
17104 KB |
Output is correct |
63 |
Correct |
454 ms |
106648 KB |
Output is correct |
64 |
Correct |
425 ms |
48208 KB |
Output is correct |
65 |
Correct |
423 ms |
48028 KB |
Output is correct |
66 |
Correct |
410 ms |
48252 KB |
Output is correct |
67 |
Correct |
446 ms |
110768 KB |
Output is correct |
68 |
Correct |
446 ms |
110868 KB |
Output is correct |
69 |
Correct |
469 ms |
110796 KB |
Output is correct |
70 |
Correct |
55 ms |
21716 KB |
Output is correct |
71 |
Correct |
54 ms |
21712 KB |
Output is correct |
72 |
Correct |
55 ms |
21668 KB |
Output is correct |
73 |
Correct |
55 ms |
21712 KB |
Output is correct |
74 |
Correct |
54 ms |
21664 KB |
Output is correct |
75 |
Correct |
54 ms |
21716 KB |
Output is correct |
76 |
Correct |
60 ms |
21724 KB |
Output is correct |
77 |
Correct |
54 ms |
21700 KB |
Output is correct |
78 |
Correct |
54 ms |
21716 KB |
Output is correct |
79 |
Correct |
55 ms |
21716 KB |
Output is correct |
80 |
Correct |
54 ms |
21712 KB |
Output is correct |
81 |
Correct |
55 ms |
21708 KB |
Output is correct |
82 |
Correct |
57 ms |
21708 KB |
Output is correct |
83 |
Correct |
64 ms |
21716 KB |
Output is correct |
84 |
Correct |
59 ms |
21716 KB |
Output is correct |
85 |
Correct |
56 ms |
21716 KB |
Output is correct |
86 |
Correct |
55 ms |
21716 KB |
Output is correct |
87 |
Correct |
54 ms |
21664 KB |
Output is correct |
88 |
Correct |
54 ms |
21712 KB |
Output is correct |
89 |
Correct |
57 ms |
21696 KB |
Output is correct |
90 |
Correct |
54 ms |
21704 KB |
Output is correct |