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>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N=3005;
int n,m,dp[N][3];
bool can[N][N][3];
char a[N][N];
vector<pii>vec[N*2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
vec[i+j].push_back(mp(i,j));
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i-1][j]=='R'&&a[i][j]=='G'&&a[i+1][j]=='W') can[i][j][1]=true;
if(a[i][j-1]=='R'&&a[i][j]=='G'&&a[i][j+1]=='W') can[i][j][2]=true;
}
}
int res=0;
for(int s=2;s<=n+m;s++)
{
memset(dp,0,sizeof dp);
int sz=vec[s].size();
for(int i=1;i<=sz;i++)
{
int x=vec[s][i-1].fi;
int y=vec[s][i-1].se;
dp[i][0]=max({dp[i-1][0],dp[i-1][1],dp[i-1][2]});
for(int j=1;j<=2;j++) if(can[x][y][j]) dp[i][j]=max(dp[i-1][0],dp[i-1][j])+1;
}
res=res+max({dp[sz][0],dp[sz][1],dp[sz][2]});
}
cout<<res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |