답안 #441255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441255 2021-07-04T18:37:20 Z Aryan_Raina Dango Maker (JOI18_dango_maker) C++17
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
#define ld long double
#define ar array
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1e9+7;
const int INF = 1e15+5;

void amax(int &a, int b) { a = max(a, b); }

void solve() {
    int N, M; cin >> N >> M;
    string s[N];
    for (string &i : s) cin >> i;

    auto right = [&](int i, int j) {
        if (j + 2 >= M) return false;
        return s[i][j] == 'R' && s[i][j+1] == 'G' && s[i][j+2] == 'W';
    };
    auto down = [&](int i, int j) {
        if (i + 2 >= N) return false;
        return s[i][j] == 'R' && s[i+1][j] == 'G' && s[i+2][j] == 'W';
    };

    int ans = 0;
    for (int x = 0; x < N; x++) {
        vector<ar<int,3>> dp(M, {0,0,0});

        if (down(x, 0)) dp[0][1] = dp[0][0] = 1;
        if (right(x, 0)) dp[0][2] = 1;

        int mx = max({dp[0][0], dp[0][1], dp[0][2]});
        cout << x << ' ' << 0 << " : ";
        cout << dp[0][0] << ' ' << dp[0][1] << ' ' << dp[0][2] << '\n';

        for (int i = x-1, j = 1; j < M && i >= 0; i--, j++) {
            if (down(i, j))
                amax(dp[j][1], dp[j-1][0] + 1);

            if (right(i, j)) {
                amax(dp[j][2], max(dp[j-1][0], dp[j-1][2]) + 1);
                if (j - 2 >= 0) amax(dp[j][2], dp[j-2][2] + 1);
            }
            
            amax(dp[j][0], max(dp[j-1][0], dp[j][1]));
            if (j - 2 >= 0) amax(dp[j][0], dp[j-2][2]);

            amax(mx, max({dp[j][0], dp[j][1], dp[j][2]}));
        }

        ans += mx;
    }

    for (int x = 1; x < M; x++) {
        vector<ar<int,3>> dp(M, {0,0,0});

        if (down(N-1, x)) dp[x][1] = dp[x][0] = 1;
        if (right(N-1, x)) dp[x][2] = 1;

        int mx = max({dp[x][0], dp[x][1], dp[x][2]});

        for (int i = N-2, j = x + 1; j < M && i >= 0; i--, j++) {
            if (down(i, j))
                amax(dp[j][1], dp[j-1][0] + 1);

            if (right(i, j)) {
                amax(dp[j][2], max(dp[j-1][0], dp[j-1][2]) + 1);
                if (j - 2 >= 0) amax(dp[j][2], dp[j-2][2] + 1);
            }
            
            amax(dp[j][0], max(dp[j-1][0], dp[j][1]));
            if (j - 2 >= 0) amax(dp[j][0], dp[j-2][2]);

            amax(mx, max({dp[j][0], dp[j][1], dp[j][2]}));
        }
        
        ans += mx;
    }

    cout << ans << '\n';
}
 
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); 
 
    int t = 1; //cin >> t;
    while (t--) solve();   
}  
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -