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;
char a[3005][3005];
int dp[3][3005][3005];
int main(){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
cin>>a[i][j];
int ans=0;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
dp[0][i][j] = max(dp[0][i - 1][j+1],max(dp[1][i-1][j+1],dp[2][i-1][j+1]));
if (a[i][j]=='G') {
if (a[i][j - 1] == 'R' && a[i][j + 1] == 'W')
dp[1][i][j] = max(dp[1][i - 1][j + 1],dp[0][i - 1][j + 1]) + 1;
if (a[i - 1][j] == 'R' && a[i + 1][j] == 'W')
dp[2][i][j] = max(dp[2][i - 1][j + 1],dp[0][i - 1][j + 1]) + 1;
}
if (i == n || j == 1) ans+=max(dp[0][i][j],max(dp[1][i][j],dp[2][i][j]));
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |