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 int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
char a[3005][3005];
vector <int> ind[6005];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
ind[i+j].pb(i);
}
}
int ans=0;
for(int i=0;i<n+m-1;i++){
int dp[ind[i].size()+1][3];
dp[ind[i].size()][0]=0;
dp[ind[i].size()][1]=0;
dp[ind[i].size()][2]=0;
for(int j=ind[i].size()-1;j>=0;j--){
int x=ind[i][j],y=i-ind[i][j];
dp[j][0]=0;dp[j][1]=0;dp[j][2]=0;
dp[j][0]=max({dp[j+1][0],dp[j+1][1],dp[j+1][2]});
if(y+1<m && y-1>=0 && a[x][y]=='G' && a[x][y+1]=='W' && a[x][y-1]=='R'){
dp[j][1]=max(dp[j+1][0],dp[j+1][1])+1;
}
if(x+1<n && x-1>=0 && a[x][y]=='G' && a[x+1][y]=='W' && a[x-1][y]=='R'){
dp[j][2]=max(dp[j+1][0],dp[j+1][2])+1;
}
}
ans+=max({dp[0][0],dp[0][1],dp[0][2]});
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |