extern "C" int __lsan_is_turned_off() { // YAYY
        return 1; };
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
struct { template<typename T> operator T() { T x; cin>>x; return x; } } in;
int main()
{
        int n=in, m=in;
        
        vector mp(n, vector<char>(m));
        
        for(auto&r:mp)for(auto&c:r)c=in;
        
        int ans=0;
        for(int i=0;i<n+m-1;i++) {
                int x,y;
                if(i<m) y=0,x=i;
                else x=m-1, y=i-m+1;
                
                auto f = [&](int i, int j) -> int {
                        if(i<0||i>=m||j<0||j>=n) return 0;
                        return mp[j][i] == 'R';
                };
                auto g = [&](int i, int j) -> int {
                        if(i<0||i>=m||j<0||j>=n) return 0;
                        return mp[j][i] == 'W';
                };
                
                int dp1=0, dp2=0, dp3=0;
                while(x>=0 && y<n) {
                        int ndp1=0, ndp2=0, ndp3=0;
                        ndp3 = max({dp1, dp2, dp3});
                        ndp1 = max(dp3, dp1) + f(x-1,y) * (mp[y][x]=='G') * g(x+1,y);
                        ndp2 = max(dp3, dp2) + f(x,y-1) * (mp[y][x]=='G') * g(x,y+1);
                        dp1 = ndp1;
                        dp2 = ndp2;
                        dp3 = ndp3;
                        x--;y++;
                }
                ans += max({dp1, dp2, dp3});
        }
        printf("%d\n",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... |