Submission #210418

#TimeUsernameProblemLanguageResultExecution timeMemory
210418SamAndDango Maker (JOI18_dango_maker)C++17
100 / 100
164 ms18040 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 3003;

int n, m;
char a[N][N];

int dp[N][3];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf(" %s", (a[i] + 1));
    int ans = 0;
    for (int si = 1; si <= n; ++si)
    {
        memset(dp, 0, sizeof dp);
        int x = si;
        int y = 1;
        for (int i = 1; ; ++i)
        {
            dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));
            if (a[x][y - 1] == 'R' && a[x][y] == 'G' && a[x][y + 1] == 'W')
                dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
            if (a[x - 1][y] == 'R' && a[x][y] == 'G' && a[x + 1][y] == 'W')
                dp[i][2] = max(dp[i - 1][0], dp[i - 1][2]) + 1;
            --x;
            ++y;
            if (x == 0 || y == m + 1)
            {
                ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
                break;
            }
        }
    }
    for (int sj = 2; sj <= m; ++sj)
    {
        memset(dp, 0, sizeof dp);
        int x = n;
        int y = sj;
        for (int i = 1; ; ++i)
        {
            dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));
            if (a[x][y - 1] == 'R' && a[x][y] == 'G' && a[x][y + 1] == 'W')
                dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
            if (a[x - 1][y] == 'R' && a[x][y] == 'G' && a[x + 1][y] == 'W')
                dp[i][2] = max(dp[i - 1][0], dp[i - 1][2]) + 1;
            --x;
            ++y;
            if (x == 0 || y == m + 1)
            {
                ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
                break;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message (stderr)

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
dango_maker.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %s", (a[i] + 1));
         ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...