제출 #558070

#제출 시각아이디문제언어결과실행 시간메모리
558070JomnoiDango Maker (JOI18_dango_maker)C++17
100 / 100
152 ms124024 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 3e3 + 10;

char s[MAX_N][MAX_N];
int dp[MAX_N][MAX_N][3];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    for(int i = 1; i <= N; i++) {
        cin >> (s[i] + 1);
    }

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= M; j++) {
            dp[i][j][0] = max({dp[i - 1][j + 1][0], dp[i - 1][j + 1][1], dp[i - 1][j + 1][2]});
            if(s[i][j - 1] == 'R' and s[i][j] == 'G' and s[i][j + 1] == 'W') {
                dp[i][j][1] = 1 + max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][1]);
            }
            if(s[i - 1][j] == 'R' and s[i][j] == 'G' and s[i + 1][j] == 'W') {
                dp[i][j][2] = 1 + max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][2]);
            }
        }
    }

    int ans = 0;
    for(int i = 1; i <= N; i++) {
        ans += max({dp[i][1][0], dp[i][1][1], dp[i][1][2]});
    }
    for(int i = 2; i <= M; i++) {
        ans += max({dp[N][i][0], dp[N][i][1], dp[N][i][2]});
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...