제출 #656148

#제출 시각아이디문제언어결과실행 시간메모리
656148stevancvDango Maker (JOI18_dango_maker)C++14
100 / 100
750 ms94284 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e3 + 2;
const int inf = 2e9;
int mat[N][N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> c(n + m - 1);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            char ch; cin >> ch;
            if (ch == 'R') mat[i][j] = 0;
            if (ch == 'G') mat[i][j] = 1;
            if (ch == 'W') mat[i][j] = 2;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int val = 0;
            if (j < m - 2 && mat[i][j] == 0 && mat[i][j + 1] == 1 && mat[i][j + 2] == 2) val++;
            if (i < n - 2 && mat[i][j] == 0 && mat[i + 1][j] == 1 && mat[i + 2][j] == 2) val += 2;
            c[i + j].push_back(val);
        }
    }
    int ans = 0;
    for (auto v : c) {
        int sz = v.size();
        vector<vector<int>> dp(sz + 1, vector<int>(4, -inf));
        dp[0][3] = 0;
        for (int i = 0; i < sz; i++) {
            for (int j = 0; j < 3; j++) smax(dp[i + 1][j + 1], dp[i][j]);
            smax(dp[i + 1][3], dp[i][3]);
            if (v[i] % 2 == 1) {
                dp[i + 1][3] = max(dp[i][2], dp[i][3]) + 1;
            }
            if (v[i] / 2 == 1) {
                dp[i + 1][0] = *max_element(dp[i].begin(), dp[i].end()) + 1;
            }
        }
        ans += *max_element(dp[sz].begin(), dp[sz].end());
    }
    cout << ans << en;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...