Submission #1004920

# Submission time Handle Problem Language Result Execution time Memory
1004920 2024-06-22T04:12:24 Z _callmelucian Dango Maker (JOI18_dango_maker) C++14
100 / 100
170 ms 18036 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

/*
    - dumplings order: R-G-B
    if   G on the i-th diagonal contributes to a stick
    then R is on the (i-1)-th diagonal
         W is on the (i+1)-th diagonal

    - G's on different diagonals are dependent

    - a horizontal and vertical stick on the same
    diagonal can't be placed consecutive.
*/

int dpNot[3003], dpHor[3003], dpVer[3003], n, m;
char a[3003][3003];

bool okHor (int row, int col) {
    if (row - 1 < 1 || row + 1 > n) return 0;
    return a[row - 1][col] == 'R'
        && a[row][col] == 'G'
        && a[row + 1][col] == 'W';
}

bool okVer (int row, int col) {
    if (col - 1 < 1 || col + 1 > m) return 0;
    return a[row][col - 1] == 'R'
        && a[row][col] == 'G'
        && a[row][col + 1] == 'W';
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) cin >> a[i][j];

    int ans = 0;
    for (int diag = 2; diag <= n + m; diag++) {
        int mn = max(1, diag - m), mx = min(n, diag - 1);
        for (int row = mn - 1; row <= mx; row++)
            dpNot[row] = dpHor[row] = dpVer[row] = 0;

        for (int row = mn; row <= mx; row++) {
            int col = diag - row;
            dpNot[row] = max(dpNot[row - 1], max(dpHor[row - 1], dpVer[row - 1]));
            if (okHor(row, col)) dpHor[row] = max(dpHor[row - 1], dpNot[row - 1]) + 1;
            if (okVer(row, col)) dpVer[row] = max(dpVer[row - 1], dpNot[row - 1]) + 1;
        }

        ans += max(dpNot[mx], max(dpHor[mx], dpVer[mx]));
    }

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 412 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 412 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 472 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 412 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 472 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 9304 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 1 ms 6748 KB Output is correct
58 Correct 20 ms 5724 KB Output is correct
59 Correct 167 ms 18000 KB Output is correct
60 Correct 170 ms 17916 KB Output is correct
61 Correct 165 ms 18036 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 160 ms 17744 KB Output is correct
64 Correct 116 ms 18004 KB Output is correct
65 Correct 115 ms 18000 KB Output is correct
66 Correct 109 ms 18000 KB Output is correct
67 Correct 114 ms 18004 KB Output is correct
68 Correct 112 ms 18000 KB Output is correct
69 Correct 117 ms 18004 KB Output is correct
70 Correct 13 ms 5640 KB Output is correct
71 Correct 13 ms 5724 KB Output is correct
72 Correct 13 ms 5724 KB Output is correct
73 Correct 14 ms 5756 KB Output is correct
74 Correct 15 ms 5724 KB Output is correct
75 Correct 14 ms 5724 KB Output is correct
76 Correct 11 ms 5724 KB Output is correct
77 Correct 14 ms 5864 KB Output is correct
78 Correct 13 ms 5724 KB Output is correct
79 Correct 13 ms 5720 KB Output is correct
80 Correct 11 ms 5720 KB Output is correct
81 Correct 12 ms 5632 KB Output is correct
82 Correct 13 ms 5724 KB Output is correct
83 Correct 13 ms 5736 KB Output is correct
84 Correct 13 ms 5724 KB Output is correct
85 Correct 14 ms 5756 KB Output is correct
86 Correct 13 ms 5720 KB Output is correct
87 Correct 15 ms 5720 KB Output is correct
88 Correct 13 ms 5720 KB Output is correct
89 Correct 13 ms 5724 KB Output is correct
90 Correct 13 ms 5548 KB Output is correct