#include<bits/stdc++.h>
#define int long long
#define ss second
#define ff first
#define pb push_back
#define endl "\n"
const int mxn=30005;
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
char s[n+5][m+5];
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cin>>s[i][j];
}
}
vector<int> v[n+m+5];
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
int cur=0;
if((i>1&&s[i-1][j]=='R')&&s[i][j]=='G'&&(i<n&&s[i+1][j]=='W')){
cur+=1;
}
if((j>1&&s[i][j-1]=='R')&&s[i][j]=='G'&&(j<m&&s[i][j+1]=='W')){
cur+=2;
}
v[i+j].pb(cur);
}
}
int mx=0;
vector<int> dp(3),dp1(3);
for(int i=2; i<=n+m; i++){
fill(dp.begin(),dp.end(),0);
for(auto num:v[i]) {
for(int j=0; j<3; j++){
dp1[j]=dp[j];
dp[j]=0;
}
dp[0]=max({dp1[0],dp1[1],dp1[2]});
if(num&1) dp[1]=max(dp1[0],dp1[1])+1;
if(num&2) dp[2]=max(dp1[0],dp1[2])+1;
}
mx+=max({dp[0],dp[1],dp[2]});
}
cout<<mx;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |