Submission #621461

#TimeUsernameProblemLanguageResultExecution timeMemory
621461elkernosDango Maker (JOI18_dango_maker)C++17
100 / 100
1004 ms18456 KiB
#include <bits/stdc++.h>

using namespace std;

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector g(n + 1, vector<char>(m + 1));
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> g[i][j];
        }
    }
    int ans = 0;
    for(int s = 2; s <= n + m; s++) {
        vector dp(n + 1, vector<int>(3));
        int p = 0;
        for(int i = 1, j = s - i; i <= n; i++, j--) {
            if(!(1 <= j && j <= m)) {
                continue;
            }
            dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
            if(g[i][j] == 'G') {
                if(1 < i && i < n && g[i - 1][j] == 'R' && g[i + 1][j] == 'W') {
                    dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
                }
                if(1 < j && j < m && g[i][j - 1] == 'R' && g[i][j + 1] == 'W') {
                    dp[i][2] = max(dp[i - 1][0], dp[i - 1][2]) + 1;
                }
            }
            p = i;
        }
        ans += max({dp[p][0], dp[p][1], dp[p][2]});
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...