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 <iostream>
#include <fstream>
using namespace std;
const int nmax=3005;
int dp[nmax][nmax][2];
string s[nmax];
int n,m,i,j,ans;
int main()
{
ios_base::sync_with_stdio(false);
//freopen("data.in","r",stdin);
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>s[i];
s[i]=" "+s[i]+" ";
}
for(i=1;i<=m+1;i++)
s[0]+=" ",s[n+1]+=" ";
for(i=1;i<=n;i++)
for(j=m;j>=1;j--)
{
dp[i][j][0]=max(dp[i-1][j+1][0],dp[i-1][j+1][1]);
dp[i][j][1]=max(dp[i-1][j+1][0],dp[i-1][j+1][1]);
if(s[i][j]=='G')
{
if(s[i-1][j]=='R'&&s[i+1][j]=='W') dp[i][j][0]=max(dp[i-1][j+1][0]+1,dp[i][j][0]);
if(s[i][j-1]=='R'&&s[i][j+1]=='W') dp[i][j][1]=max(dp[i-1][j+1][1]+1,dp[i][j][1]);
}
if(j==1||i==n) ans+=max(dp[i][j][0],dp[i][j][1]);
}
cout<<ans;
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... |