Submission #899303

#TimeUsernameProblemLanguageResultExecution timeMemory
899303viwlesxqDango Maker (JOI18_dango_maker)C++17
100 / 100
393 ms194948 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S &a, const T &b) {
    return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
    return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 1e9 + 7;

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, m; cin >> n >> m;
    char s[n + 1][m + 1];
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> s[i][j];
        }
    }
    int res = 0;
    vector<array<int, 2>> di[n + m - 1];
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            di[i + j - 2].push_back({i, j});
        }
    }
    for (auto arr : di) {
        if (arr.empty()) continue;
        int t = size(arr);
        int dp[t][3];
        memset(dp, 0, sizeof(dp));
        for (int i = 0; i < t; ++i) {
            auto [x, y] = arr[i];
            if (i > 0)
                dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
            if (x - 1 >= 1 && x + 1 <= n && s[x - 1][y] == 'R' && s[x][y] == 'G' && s[x + 1][y] == 'W')
                dp[i][1] = (i > 0 ? max(dp[i - 1][0], dp[i - 1][1]) : 0ll) + 1;
            if (y - 1 >= 1 && y + 1 <= m && s[x][y - 1] == 'R' && s[x][y] == 'G' && s[x][y + 1] == 'W')
                dp[i][2] = (i > 0 ? max(dp[i - 1][0], dp[i - 1][2]) : 0ll) + 1;
        }
        res += max({dp[t - 1][0], dp[t - 1][1], dp[t - 1][2]});
    }
    cout << res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...