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;
const int N=3002;
int n,m;
int ans;
int dp[N][N][3];
bool vis[N][N][3];
string s[N];
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> s[i];
s[i]="x"+s[i];
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(s[i][j]=='G'){
if(j>1&&s[i][j-1]=='R'&&j<m&&s[i][j+1]=='W'){
if(!vis[i-1][j+1][1])dp[i][j][1]=dp[i-1][j+1][0]+dp[i-1][j+1][1]+1;
else dp[i][j][1]=max(dp[i-1][j+1][0],dp[i-1][j+1][1]+1);
vis[i][j][1]=true;
}
if(i>1&&s[i-1][j]=='R'&&i<n&&s[i+1][j]=='W'){
if(!vis[i-1][j+1][2])dp[i][j][2]=dp[i-1][j+1][0]+dp[i-1][j+1][2]+1;
else dp[i][j][2]=max(dp[i-1][j+1][0],dp[i-1][j+1][2]+1);
vis[i][j][2]=true;
}
}
dp[i][j][0]=max(dp[i-1][j+1][0],max(dp[i-1][j+1][2],dp[i-1][j+1][1]));
}
dp[i][0][0]=max(dp[i-1][1][0],max(dp[i-1][1][2],dp[i-1][1][1]));
for(int j=0; j<=m; j++){
dp[n+1][j][0]=max(dp[n][j+1][0],max(dp[n][j+1][2],dp[n][j+1][1]));
}
}
for(int i=1; i<=n+1; i++)ans+=dp[i][0][0];
for(int j=1; j<=m; j++)ans+=dp[n+1][j][0];
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |