Submission #375687

# Submission time Handle Problem Language Result Execution time Memory
375687 2021-03-09T16:54:08 Z valerikk Dango Maker (JOI18_dango_maker) C++17
100 / 100
1886 ms 18540 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
//   R
//  RG
// RGW
// GW
// W

const int INF = 1e9;

int solve(vector<int> d, vector<int> r) {
    int n = d.size();
    vector<vector<int>> dp(3, vector<int>(3, -INF));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        vector<vector<int>> ndp(3, vector<int>(3, -INF));
        for (int x = 0; x < 3; ++x) {
            for (int y = 0; y < 3; ++y) {
                if (dp[x][y] == -INF) continue;
                for (int z = 0; z < 3; ++z) {
                    if (z == 1 && (x == 2 || y == 2 || !d[i])) continue;
                    if (z == 2 && !r[i]) continue;
                    ndp[y][z] = max(ndp[y][z], dp[x][y] + !!z);
                }
            }
        }
        dp = ndp;
    }
    int ans = 0;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) ans = max(ans, dp[i][j]);
    }
    return ans;
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<char>> grid(n, vector<char>(m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> grid[i][j];
        }
    }
    auto can_down = [&](int x, int y) {
        if (x + 2 < n && grid[x][y] == 'R' && grid[x + 1][y] == 'G' && grid[x + 2][y] == 'W') return 1;
        return 0;
    };
    auto can_right = [&](int x, int y) {
        if (y + 2 < m && grid[x][y] == 'R' && grid[x][y + 1] == 'G' && grid[x][y + 2] == 'W') return 1;
        return 0;
    };
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (i == n - 1 || j == 0) {
                vector<int> d, r;
                int curi = i, curj = j;
                while (curi >= 0 && curj < m) {
                    d.push_back(can_down(curi, curj));
                    r.push_back(can_right(curi, curj));
                    --curi;
                    ++curj;
                }
                ans += solve(d, r);
            }
        }
    }
    cout << ans << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 2 ms 364 KB Output is correct
55 Correct 2 ms 492 KB Output is correct
56 Correct 5 ms 364 KB Output is correct
57 Correct 7 ms 492 KB Output is correct
58 Correct 184 ms 1516 KB Output is correct
59 Correct 1683 ms 9472 KB Output is correct
60 Correct 1715 ms 9580 KB Output is correct
61 Correct 1672 ms 9664 KB Output is correct
62 Correct 2 ms 364 KB Output is correct
63 Correct 1627 ms 9196 KB Output is correct
64 Correct 1881 ms 18452 KB Output is correct
65 Correct 1886 ms 18284 KB Output is correct
66 Correct 1841 ms 18540 KB Output is correct
67 Correct 1722 ms 18412 KB Output is correct
68 Correct 1686 ms 18208 KB Output is correct
69 Correct 1717 ms 18384 KB Output is correct
70 Correct 205 ms 2540 KB Output is correct
71 Correct 204 ms 2412 KB Output is correct
72 Correct 253 ms 2444 KB Output is correct
73 Correct 204 ms 2412 KB Output is correct
74 Correct 221 ms 2412 KB Output is correct
75 Correct 203 ms 2540 KB Output is correct
76 Correct 212 ms 2412 KB Output is correct
77 Correct 213 ms 2540 KB Output is correct
78 Correct 211 ms 2488 KB Output is correct
79 Correct 207 ms 2540 KB Output is correct
80 Correct 205 ms 2412 KB Output is correct
81 Correct 203 ms 2412 KB Output is correct
82 Correct 206 ms 2412 KB Output is correct
83 Correct 208 ms 2540 KB Output is correct
84 Correct 209 ms 2540 KB Output is correct
85 Correct 202 ms 2412 KB Output is correct
86 Correct 202 ms 2540 KB Output is correct
87 Correct 208 ms 2412 KB Output is correct
88 Correct 206 ms 2540 KB Output is correct
89 Correct 235 ms 2488 KB Output is correct
90 Correct 219 ms 2540 KB Output is correct