This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |