제출 #206539

#제출 시각아이디문제언어결과실행 시간메모리
206539stefdascaDango Maker (JOI18_dango_maker)C++14
100 / 100
543 ms141432 KiB
#include<bits/stdc++.h>
using namespace std;
int n, m;
char a[3005][3005];
bool okh[3005][3005], okv[3005][3005];

int dp[3002][3002][3];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        cin >> (a[i] + 1);
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
        {
            if(a[i][j-1] == 'R' && a[i][j] == 'G' && a[i][j+1] == 'W')
                okh[i][j] = 1;
            if(a[i-1][j] == 'R' && a[i][j] == 'G' && a[i+1][j] == 'W')
                okv[i][j] = 1;
        }
    int L = 1, C = 1;
    int ans = 0;
    for(int i = 2; i <= n+m; ++i)
    {
        int sL = L, sC = C;
        dp[sL][sC][0] = 0;
        dp[sL][sC][1] = okv[sL][sC];
        dp[sL][sC][2] = okh[sL][sC];
        --sL, ++sC;
        while(sL && sC <= m)
        {
            for(int j = 0; j <= 2; ++j)
                dp[sL][sC][0] = max(dp[sL][sC][0], dp[sL + 1][sC - 1][j]);
            dp[sL][sC][1] = max(dp[sL + 1][sC - 1][1], dp[sL + 1][sC - 1][0]) + okv[sL][sC];
            dp[sL][sC][2] = max(dp[sL + 1][sC - 1][2], dp[sL + 1][sC - 1][0]) + okh[sL][sC];
            --sL, ++sC;
        }
        ++L;
        if(L > n)
        {
            L = n;
            ++C;
        }
        ++sL, --sC;
        ans = ans + max(dp[sL][sC][0], max(dp[sL][sC][1], dp[sL][sC][2]));
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...