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 int long long
#define pb push_back
#define ff first
#define ss second
const int N=3005;
char a[N][N];
bool vis[N][N];
int cnt=0;
int dp[N][N];
signed main(){
int n,m;
cin>>n>>m;
for(int i=1+3;i<=n+3;i++){
for(int j=1+3;j<=m+3;j++){
cin>>a[i][j];
}
}
for(int i=1+3;i<=n+3;i++){
for(int j=1+3;j<=m+3;j++){
dp[i][j]=max(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1],dp[i][j]);
if(a[i][j]=='W' and a[i][j-1]=='G' and a[i][j-2]=='R'){
dp[i][j]=max(dp[i][j],dp[i-1][j]+dp[i][j-3]-dp[i-1][j-3]+1);
}
if(a[i][j]=='W' and a[i-1][j]=='G' and a[i-2][j]=='R'){
dp[i][j]=max(dp[i][j],dp[i][j-1]+dp[i-3][j]-dp[i-3][j-1]+1);
}
}
}
cout<<dp[n+3][m+3];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |