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 MAXN 3010
#define MAXM 6020
#define INF 1000000007
bool moze[MAXM][MAXN][2];
char s[MAXN][MAXN];
long long dp [MAXN][2][2];
int main()
{
long long n,m;
cin>>n>>m;
for (long long i=1;i<=n;i++)
{
for (long long j=1;j<=m;j++)
{
cin>>s[i][j];
}
}
for (long long i=1;i<=n;i++)
{
for (long long j=1;j<=n;j++)
{
if (s[i][j]=='R' and s[i][j+1]=='G' and s[i][j+2]=='W') moze[i+j][i][0]=1;
if (s[i][j]=='R' and s[i+1][j]=='G' and s[i+2][j]=='W') moze[i+j][i][1]=1;
}
}
long long ans=0;
for (long long z=2;z<=n+m;z++)
{
for (long long i=0;i<MAXN;i++) dp[i][0][0]=dp[i][0][1]=dp[i][1][0]=dp[i][1][1]=-INF;
dp[0][0][0]=0;
for (long long i=1;i<=n;i++)
{
for (int x=0;x<=1;x++)
{
for (int y=0;y<=1;y++)
{
dp[i][0][x]=max(dp[i][0][x],dp[i-1][x][y]);
if (moze[z][i][0] and x==0 and y==0)dp[i][0][x]=max(dp[i][0][x],dp[i-1][x][y]+1);
if (moze[z][i][1]) dp[i][1][x]=max(dp[i][1][x],dp[i-1][x][y]+1);
}
}
}
long long tmp=0;
for (int x=0;x<2;x++)
{
for (int y=0;y<2;y++)
{
tmp=max(tmp,dp[n][x][y]);
}
}
ans+=tmp;
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |