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 <string.h>
using namespace std;
int dp[5005][3][3],n,m;
char arr[5005][5005];
int solve(int i,int x,int y,int a,int b)
{
if (!x || y>m)
return 0;
if (dp[i][a][b]!=-1)
return dp[i][a][b];
int ans=solve(i+1,x-1,y+1,0,a);
if (arr[x][y]=='R')
{
if (arr[x][y+1]=='G' && arr[x][y+2]=='W')
ans=max(ans,solve(i+1,x-1,y+1,1,a)+1);
if (arr[x+1][y]=='G' && arr[x+2][y]=='W' && a!=1 && b!=1)
ans=max(ans,solve(i+1,x-1,y+1,2,a)+1);
}
return dp[i][a][b]=ans;
}
int main()
{
int ans=0;
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
scanf(" %c",&arr[i][j]);
}
for (int i=1;i<n+m;i++)
{
memset(dp,-1,sizeof(dp));
ans+=solve(0,min(i,n),max(1,i-n+1),0,0);
}
printf("%d",ans);
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
dango_maker.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&arr[i][j]);
~~~~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |