Submission #563797

# Submission time Handle Problem Language Result Execution time Memory
563797 2022-05-18T06:46:43 Z KoD Bowling (BOI15_bow) C++17
100 / 100
200 ms 3532 KB
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); ++i)

using ll = long long;
using std::vector;

ll dp[10][331][11][11];

bool match(const char c, const char d) {
    return c == '?' or c == d;
}

ll solve(const int N, const std::string& S, const std::vector<int>& P) {
    rep(i, 10) rep(j, 331) rep(k, 11) rep(l, 11) dp[i][j][k][l] = 0;
    rep(k, 11) rep(l, 11) dp[0][0][k][l] = 1;

    rep(i, N - 1) rep(j, 331) rep(k, 11) rep(l, 11) {
        const ll val = dp[i][j][k][l];
        if (val == 0)
            continue;

        const auto C = S.begin() + (2 * i);

        if (k == 10) {
            if (match(C[0], 'x') and match(C[1], '-')) {
                rep(m, 11) {
                    const int nj = j + 10 + l + m;
                    if (P[i] == -1 or P[i] == nj) {
                        dp[i + 1][nj][l][m] += val;
                    }
                }
            }
        } else {
            if (k + l <= 10 and match(C[0], char('0' + k))) {
                rep(m, 11) {
                    int nj = j;
                    if (k + l == 10) {
                        if (!match(C[1], '/'))
                            continue;
                        nj += 10 + m;
                    } else {
                        if (!match(C[1], char('0' + l)))
                            continue;
                        nj += k + l;
                    }
                    if (P[i] == -1 or P[i] == nj) {
                        rep(n, 11) dp[i + 1][nj][m][n] += val;
                    }
                }
            }
        }
    }

    const auto C = S.begin() + (2 * N - 2);
    ll ret = 0;
    rep(j, 331) {
        const auto check = [&](const int add) { return P[N - 1] == -1 or P[N - 1] == j + add; };
        if (match(C[0], 'x')) {
            if (match(C[1], 'x')) {
                if (match(C[2], 'x')) {
                    if (check(10 + 10 + 10)) {
                        ret += dp[N - 1][j][10][10];
                    }
                }
                rep(m, 10) {
                    if (match(C[2], char('0' + m)) and check(10 + 10 + m)) {
                        ret += dp[N - 1][j][10][10];
                    }
                }
            }
            rep(l, 10) {
                rep(m, 11) {
                    if (l + m == 10 and match(C[1], char('0' + l)) and match(C[2], '/') and
                        check(10 + l + m)) {
                        ret += dp[N - 1][j][10][l];
                    }
                    if (l + m < 10 and match(C[1], char('0' + l)) and
                        match(C[2], char('0' + m)) and check(10 + l + m)) {
                        ret += dp[N - 1][j][10][l];
                    }
                }
            }
        }
        rep(k, 10) {
            rep(l, 11) {
                if (k + l == 10 and match(C[0], char('0' + k)) and match(C[1], '/')) {
                    if (match(C[2], 'x') and check(10 + 10)) {
                        ret += dp[N - 1][j][k][l];
                    }
                    rep(m, 10) {
                        if (match(C[2], char('0' + m)) and check(10 + m)) {
                            ret += dp[N - 1][j][k][l];
                        }
                    }
                }
                if (k + l < 10 and match(C[0], char('0' + k)) and match(C[1], char('0' + l)) and
                    match(C[2], '-') and check(k + l)) {
                    ret += dp[N - 1][j][k][l];
                }
            }
        }
    }
    return ret;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int Q;
    std::cin >> Q;
    while (Q--) {
        int N;
        std::cin >> N;
        std::string S;
        std::cin >> S;
        vector<int> P(N);
        for (auto& x : P) {
            std::cin >> x;
        }
        std::cout << solve(N, S, P) << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 3412 KB Output is correct
2 Correct 14 ms 3412 KB Output is correct
3 Correct 13 ms 3448 KB Output is correct
4 Correct 14 ms 3452 KB Output is correct
5 Correct 14 ms 3412 KB Output is correct
6 Correct 15 ms 3412 KB Output is correct
7 Correct 16 ms 3412 KB Output is correct
8 Correct 18 ms 3452 KB Output is correct
9 Correct 16 ms 3412 KB Output is correct
10 Correct 17 ms 3448 KB Output is correct
11 Correct 19 ms 3452 KB Output is correct
12 Correct 14 ms 3456 KB Output is correct
13 Correct 4 ms 3412 KB Output is correct
14 Correct 15 ms 3452 KB Output is correct
15 Correct 4 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3452 KB Output is correct
2 Correct 24 ms 3448 KB Output is correct
3 Correct 20 ms 3432 KB Output is correct
4 Correct 19 ms 3412 KB Output is correct
5 Correct 19 ms 3452 KB Output is correct
6 Correct 22 ms 3452 KB Output is correct
7 Correct 23 ms 3452 KB Output is correct
8 Correct 22 ms 3448 KB Output is correct
9 Correct 20 ms 3456 KB Output is correct
10 Correct 46 ms 3532 KB Output is correct
11 Correct 36 ms 3412 KB Output is correct
12 Correct 33 ms 3412 KB Output is correct
13 Correct 35 ms 3412 KB Output is correct
14 Correct 24 ms 3412 KB Output is correct
15 Correct 24 ms 3452 KB Output is correct
16 Correct 24 ms 3412 KB Output is correct
17 Correct 25 ms 3452 KB Output is correct
18 Correct 45 ms 3412 KB Output is correct
19 Correct 46 ms 3412 KB Output is correct
20 Correct 49 ms 3436 KB Output is correct
21 Correct 53 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3452 KB Output is correct
2 Correct 15 ms 3412 KB Output is correct
3 Correct 16 ms 3452 KB Output is correct
4 Correct 15 ms 3412 KB Output is correct
5 Correct 15 ms 3412 KB Output is correct
6 Correct 21 ms 3412 KB Output is correct
7 Correct 19 ms 3448 KB Output is correct
8 Correct 19 ms 3412 KB Output is correct
9 Correct 22 ms 3412 KB Output is correct
10 Correct 23 ms 3456 KB Output is correct
11 Correct 22 ms 3448 KB Output is correct
12 Correct 23 ms 3412 KB Output is correct
13 Correct 21 ms 3412 KB Output is correct
14 Correct 22 ms 3452 KB Output is correct
15 Correct 21 ms 3412 KB Output is correct
16 Correct 22 ms 3456 KB Output is correct
17 Correct 22 ms 3412 KB Output is correct
18 Correct 19 ms 3452 KB Output is correct
19 Correct 18 ms 3452 KB Output is correct
20 Correct 18 ms 3412 KB Output is correct
21 Correct 18 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3412 KB Output is correct
2 Correct 15 ms 3412 KB Output is correct
3 Correct 19 ms 3448 KB Output is correct
4 Correct 18 ms 3452 KB Output is correct
5 Correct 16 ms 3412 KB Output is correct
6 Correct 14 ms 3412 KB Output is correct
7 Correct 14 ms 3412 KB Output is correct
8 Correct 13 ms 3412 KB Output is correct
9 Correct 15 ms 3448 KB Output is correct
10 Correct 48 ms 3440 KB Output is correct
11 Correct 47 ms 3412 KB Output is correct
12 Correct 46 ms 3412 KB Output is correct
13 Correct 44 ms 3412 KB Output is correct
14 Correct 20 ms 3452 KB Output is correct
15 Correct 22 ms 3452 KB Output is correct
16 Correct 21 ms 3452 KB Output is correct
17 Correct 20 ms 3412 KB Output is correct
18 Correct 20 ms 3412 KB Output is correct
19 Correct 19 ms 3412 KB Output is correct
20 Correct 16 ms 3412 KB Output is correct
21 Correct 18 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 3412 KB Output is correct
2 Correct 14 ms 3412 KB Output is correct
3 Correct 13 ms 3448 KB Output is correct
4 Correct 14 ms 3452 KB Output is correct
5 Correct 14 ms 3412 KB Output is correct
6 Correct 15 ms 3412 KB Output is correct
7 Correct 16 ms 3412 KB Output is correct
8 Correct 18 ms 3452 KB Output is correct
9 Correct 16 ms 3412 KB Output is correct
10 Correct 17 ms 3448 KB Output is correct
11 Correct 19 ms 3452 KB Output is correct
12 Correct 14 ms 3456 KB Output is correct
13 Correct 4 ms 3412 KB Output is correct
14 Correct 15 ms 3452 KB Output is correct
15 Correct 4 ms 3412 KB Output is correct
16 Correct 17 ms 3452 KB Output is correct
17 Correct 24 ms 3448 KB Output is correct
18 Correct 20 ms 3432 KB Output is correct
19 Correct 19 ms 3412 KB Output is correct
20 Correct 19 ms 3452 KB Output is correct
21 Correct 22 ms 3452 KB Output is correct
22 Correct 23 ms 3452 KB Output is correct
23 Correct 22 ms 3448 KB Output is correct
24 Correct 20 ms 3456 KB Output is correct
25 Correct 46 ms 3532 KB Output is correct
26 Correct 36 ms 3412 KB Output is correct
27 Correct 33 ms 3412 KB Output is correct
28 Correct 35 ms 3412 KB Output is correct
29 Correct 24 ms 3412 KB Output is correct
30 Correct 24 ms 3452 KB Output is correct
31 Correct 24 ms 3412 KB Output is correct
32 Correct 25 ms 3452 KB Output is correct
33 Correct 45 ms 3412 KB Output is correct
34 Correct 46 ms 3412 KB Output is correct
35 Correct 49 ms 3436 KB Output is correct
36 Correct 53 ms 3412 KB Output is correct
37 Correct 20 ms 3452 KB Output is correct
38 Correct 15 ms 3412 KB Output is correct
39 Correct 16 ms 3452 KB Output is correct
40 Correct 15 ms 3412 KB Output is correct
41 Correct 15 ms 3412 KB Output is correct
42 Correct 21 ms 3412 KB Output is correct
43 Correct 19 ms 3448 KB Output is correct
44 Correct 19 ms 3412 KB Output is correct
45 Correct 22 ms 3412 KB Output is correct
46 Correct 23 ms 3456 KB Output is correct
47 Correct 22 ms 3448 KB Output is correct
48 Correct 23 ms 3412 KB Output is correct
49 Correct 21 ms 3412 KB Output is correct
50 Correct 22 ms 3452 KB Output is correct
51 Correct 21 ms 3412 KB Output is correct
52 Correct 22 ms 3456 KB Output is correct
53 Correct 22 ms 3412 KB Output is correct
54 Correct 19 ms 3452 KB Output is correct
55 Correct 18 ms 3452 KB Output is correct
56 Correct 18 ms 3412 KB Output is correct
57 Correct 18 ms 3412 KB Output is correct
58 Correct 24 ms 3412 KB Output is correct
59 Correct 15 ms 3412 KB Output is correct
60 Correct 19 ms 3448 KB Output is correct
61 Correct 18 ms 3452 KB Output is correct
62 Correct 16 ms 3412 KB Output is correct
63 Correct 14 ms 3412 KB Output is correct
64 Correct 14 ms 3412 KB Output is correct
65 Correct 13 ms 3412 KB Output is correct
66 Correct 15 ms 3448 KB Output is correct
67 Correct 48 ms 3440 KB Output is correct
68 Correct 47 ms 3412 KB Output is correct
69 Correct 46 ms 3412 KB Output is correct
70 Correct 44 ms 3412 KB Output is correct
71 Correct 20 ms 3452 KB Output is correct
72 Correct 22 ms 3452 KB Output is correct
73 Correct 21 ms 3452 KB Output is correct
74 Correct 20 ms 3412 KB Output is correct
75 Correct 20 ms 3412 KB Output is correct
76 Correct 19 ms 3412 KB Output is correct
77 Correct 16 ms 3412 KB Output is correct
78 Correct 18 ms 3456 KB Output is correct
79 Correct 39 ms 3412 KB Output is correct
80 Correct 23 ms 3412 KB Output is correct
81 Correct 24 ms 3412 KB Output is correct
82 Correct 19 ms 3412 KB Output is correct
83 Correct 19 ms 3412 KB Output is correct
84 Correct 21 ms 3412 KB Output is correct
85 Correct 22 ms 3452 KB Output is correct
86 Correct 20 ms 3412 KB Output is correct
87 Correct 22 ms 3448 KB Output is correct
88 Correct 27 ms 3448 KB Output is correct
89 Correct 32 ms 3432 KB Output is correct
90 Correct 32 ms 3412 KB Output is correct
91 Correct 33 ms 3412 KB Output is correct
92 Correct 18 ms 3412 KB Output is correct
93 Correct 192 ms 3428 KB Output is correct
94 Correct 187 ms 3436 KB Output is correct
95 Correct 190 ms 3412 KB Output is correct
96 Correct 200 ms 3428 KB Output is correct
97 Correct 186 ms 3436 KB Output is correct
98 Correct 191 ms 3532 KB Output is correct
99 Correct 190 ms 3432 KB Output is correct
100 Correct 196 ms 3412 KB Output is correct