#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
const int maxn=3e3+5;
const int MOD=1e9+7;
int n,m;
char a[maxn][maxn];
int dp[maxn][2];
bool check1(int i,int j)
{
if(j+2>m) return false;
if(a[i][j]=='R'&&a[i][j+1]=='G'&&a[i][j+2]=='W') return true;
return false;
}
bool check2(int i,int j)
{
if(i+2>n) return false;
if(a[i][j]=='R'&&a[i+1][j]=='G'&&a[i+2][j]=='W') return true;
return false;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) cin>>a[i][j];
}
int ans=0;
for(int k=1;k<=m+n;k++){
int j=min(m,k);
int res=0;
//cout<<endl;
for(int j=1;j<=m;j++) dp[j][0]=dp[j][1]=0;
for(int i=max(1,k-m+1);i<=n&&j>=1;i++){
dp[j][0]=max(dp[j+1][0],dp[j+3][1])+check1(i,j);
dp[j][1]=max(dp[j+1][1],dp[j+1][0])+check2(i,j);
res=max({res,dp[j][0],dp[j][1]});
//cout<<i<<' '<<j<<endl;
//cout<<dp[j][0]<<' '<<dp[j][1]<<endl;
j--;
}
ans+=res;
}
cout<<ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |