#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
char a[N][N];
int R[N][N], D[N][N];
int main() {
    int n, m, ans=0; cin >> n >> m;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++) cin >> a[i][j];
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            R[i][j] = (a[i][j] == 'G' && a[i][j-1] == 'R' && a[i][j+1] == 'W');
            D[i][j] = (a[i][j] == 'G' && a[i-1][j] == 'R' && a[i+1][j] == 'W');
        }
    }
    
    for(int i=2; i<=n+m; i++) {
        int dp[3] = { 0, 0, 0 };
        for(int j=max(1, i-m); j<min(i, n+1); j++) {
            int ndp[3] = { 0, 0, 0 };
            ndp[0] = max({ dp[0], dp[1], dp[2] });
            ndp[1] = D[j][i-j] + max({ dp[0], dp[1] });
            ndp[2] = R[j][i-j] + max({ dp[0], dp[2] });
            swap(dp, ndp);
        }
        ans += max({ dp[0], dp[1], dp[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... |