답안 #563780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
563780 2022-05-18T06:18:57 Z KoD Bowling (BOI15_bow) C++17
100 / 100
195 ms 3540 KB
#include <bits/stdc++.h>

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

using ll = long long;

using std::vector;
using std::array;
using std::pair;
using std::tuple;

template <class T> constexpr T infty = std::numeric_limits<T>::max() / 2;

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(round, N - 1) rep(point, 331) rep(k, 11) rep(l, 11) {
        const ll val = dp[round][point][k][l];
        if (val == 0) continue;

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

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

    const auto C = S.begin() + (2 * N - 2);
    ll ret = 0;
    rep(point, 331) {
        const auto check = [&](const int add) {
            return P[N - 1] == -1 or P[N - 1] == point + 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][point][10][10];
                    }
                }
                rep(m, 10) {
                    if (match(C[2], char('0' + m)) and check(10 + 10 + m)) {
                        ret += dp[N - 1][point][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][point][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][point][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][point][k][l];
                    }
                    rep(m, 10) {
                        if (match(C[2], char('0' + m)) and check(10 + m)) {
                            ret += dp[N - 1][point][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][point][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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 3460 KB Output is correct
2 Correct 16 ms 3412 KB Output is correct
3 Correct 16 ms 3456 KB Output is correct
4 Correct 23 ms 3432 KB Output is correct
5 Correct 15 ms 3412 KB Output is correct
6 Correct 15 ms 3416 KB Output is correct
7 Correct 18 ms 3412 KB Output is correct
8 Correct 16 ms 3412 KB Output is correct
9 Correct 15 ms 3456 KB Output is correct
10 Correct 17 ms 3456 KB Output is correct
11 Correct 30 ms 3436 KB Output is correct
12 Correct 24 ms 3412 KB Output is correct
13 Correct 4 ms 3412 KB Output is correct
14 Correct 29 ms 3460 KB Output is correct
15 Correct 8 ms 3416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 3456 KB Output is correct
2 Correct 19 ms 3456 KB Output is correct
3 Correct 20 ms 3460 KB Output is correct
4 Correct 18 ms 3412 KB Output is correct
5 Correct 34 ms 3412 KB Output is correct
6 Correct 22 ms 3456 KB Output is correct
7 Correct 24 ms 3452 KB Output is correct
8 Correct 24 ms 3432 KB Output is correct
9 Correct 22 ms 3412 KB Output is correct
10 Correct 39 ms 3412 KB Output is correct
11 Correct 50 ms 3412 KB Output is correct
12 Correct 31 ms 3412 KB Output is correct
13 Correct 37 ms 3412 KB Output is correct
14 Correct 40 ms 3412 KB Output is correct
15 Correct 25 ms 3412 KB Output is correct
16 Correct 25 ms 3460 KB Output is correct
17 Correct 28 ms 3456 KB Output is correct
18 Correct 48 ms 3412 KB Output is correct
19 Correct 49 ms 3412 KB Output is correct
20 Correct 53 ms 3440 KB Output is correct
21 Correct 51 ms 3436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3460 KB Output is correct
2 Correct 16 ms 3452 KB Output is correct
3 Correct 18 ms 3412 KB Output is correct
4 Correct 24 ms 3452 KB Output is correct
5 Correct 16 ms 3412 KB Output is correct
6 Correct 30 ms 3412 KB Output is correct
7 Correct 22 ms 3412 KB Output is correct
8 Correct 23 ms 3456 KB Output is correct
9 Correct 29 ms 3456 KB Output is correct
10 Correct 25 ms 3412 KB Output is correct
11 Correct 24 ms 3440 KB Output is correct
12 Correct 32 ms 3412 KB Output is correct
13 Correct 25 ms 3412 KB Output is correct
14 Correct 23 ms 3456 KB Output is correct
15 Correct 24 ms 3436 KB Output is correct
16 Correct 24 ms 3396 KB Output is correct
17 Correct 24 ms 3412 KB Output is correct
18 Correct 26 ms 3412 KB Output is correct
19 Correct 29 ms 3456 KB Output is correct
20 Correct 22 ms 3452 KB Output is correct
21 Correct 23 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 3412 KB Output is correct
2 Correct 16 ms 3456 KB Output is correct
3 Correct 21 ms 3412 KB Output is correct
4 Correct 18 ms 3360 KB Output is correct
5 Correct 17 ms 3540 KB Output is correct
6 Correct 24 ms 3444 KB Output is correct
7 Correct 22 ms 3456 KB Output is correct
8 Correct 16 ms 3460 KB Output is correct
9 Correct 15 ms 3412 KB Output is correct
10 Correct 70 ms 3412 KB Output is correct
11 Correct 53 ms 3448 KB Output is correct
12 Correct 46 ms 3412 KB Output is correct
13 Correct 57 ms 3436 KB Output is correct
14 Correct 22 ms 3412 KB Output is correct
15 Correct 26 ms 3460 KB Output is correct
16 Correct 23 ms 3412 KB Output is correct
17 Correct 20 ms 3412 KB Output is correct
18 Correct 18 ms 3400 KB Output is correct
19 Correct 26 ms 3460 KB Output is correct
20 Correct 19 ms 3412 KB Output is correct
21 Correct 17 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 3460 KB Output is correct
2 Correct 16 ms 3412 KB Output is correct
3 Correct 16 ms 3456 KB Output is correct
4 Correct 23 ms 3432 KB Output is correct
5 Correct 15 ms 3412 KB Output is correct
6 Correct 15 ms 3416 KB Output is correct
7 Correct 18 ms 3412 KB Output is correct
8 Correct 16 ms 3412 KB Output is correct
9 Correct 15 ms 3456 KB Output is correct
10 Correct 17 ms 3456 KB Output is correct
11 Correct 30 ms 3436 KB Output is correct
12 Correct 24 ms 3412 KB Output is correct
13 Correct 4 ms 3412 KB Output is correct
14 Correct 29 ms 3460 KB Output is correct
15 Correct 8 ms 3416 KB Output is correct
16 Correct 15 ms 3456 KB Output is correct
17 Correct 19 ms 3456 KB Output is correct
18 Correct 20 ms 3460 KB Output is correct
19 Correct 18 ms 3412 KB Output is correct
20 Correct 34 ms 3412 KB Output is correct
21 Correct 22 ms 3456 KB Output is correct
22 Correct 24 ms 3452 KB Output is correct
23 Correct 24 ms 3432 KB Output is correct
24 Correct 22 ms 3412 KB Output is correct
25 Correct 39 ms 3412 KB Output is correct
26 Correct 50 ms 3412 KB Output is correct
27 Correct 31 ms 3412 KB Output is correct
28 Correct 37 ms 3412 KB Output is correct
29 Correct 40 ms 3412 KB Output is correct
30 Correct 25 ms 3412 KB Output is correct
31 Correct 25 ms 3460 KB Output is correct
32 Correct 28 ms 3456 KB Output is correct
33 Correct 48 ms 3412 KB Output is correct
34 Correct 49 ms 3412 KB Output is correct
35 Correct 53 ms 3440 KB Output is correct
36 Correct 51 ms 3436 KB Output is correct
37 Correct 22 ms 3460 KB Output is correct
38 Correct 16 ms 3452 KB Output is correct
39 Correct 18 ms 3412 KB Output is correct
40 Correct 24 ms 3452 KB Output is correct
41 Correct 16 ms 3412 KB Output is correct
42 Correct 30 ms 3412 KB Output is correct
43 Correct 22 ms 3412 KB Output is correct
44 Correct 23 ms 3456 KB Output is correct
45 Correct 29 ms 3456 KB Output is correct
46 Correct 25 ms 3412 KB Output is correct
47 Correct 24 ms 3440 KB Output is correct
48 Correct 32 ms 3412 KB Output is correct
49 Correct 25 ms 3412 KB Output is correct
50 Correct 23 ms 3456 KB Output is correct
51 Correct 24 ms 3436 KB Output is correct
52 Correct 24 ms 3396 KB Output is correct
53 Correct 24 ms 3412 KB Output is correct
54 Correct 26 ms 3412 KB Output is correct
55 Correct 29 ms 3456 KB Output is correct
56 Correct 22 ms 3452 KB Output is correct
57 Correct 23 ms 3412 KB Output is correct
58 Correct 28 ms 3412 KB Output is correct
59 Correct 16 ms 3456 KB Output is correct
60 Correct 21 ms 3412 KB Output is correct
61 Correct 18 ms 3360 KB Output is correct
62 Correct 17 ms 3540 KB Output is correct
63 Correct 24 ms 3444 KB Output is correct
64 Correct 22 ms 3456 KB Output is correct
65 Correct 16 ms 3460 KB Output is correct
66 Correct 15 ms 3412 KB Output is correct
67 Correct 70 ms 3412 KB Output is correct
68 Correct 53 ms 3448 KB Output is correct
69 Correct 46 ms 3412 KB Output is correct
70 Correct 57 ms 3436 KB Output is correct
71 Correct 22 ms 3412 KB Output is correct
72 Correct 26 ms 3460 KB Output is correct
73 Correct 23 ms 3412 KB Output is correct
74 Correct 20 ms 3412 KB Output is correct
75 Correct 18 ms 3400 KB Output is correct
76 Correct 26 ms 3460 KB Output is correct
77 Correct 19 ms 3412 KB Output is correct
78 Correct 17 ms 3456 KB Output is correct
79 Correct 56 ms 3432 KB Output is correct
80 Correct 24 ms 3400 KB Output is correct
81 Correct 28 ms 3400 KB Output is correct
82 Correct 21 ms 3412 KB Output is correct
83 Correct 22 ms 3412 KB Output is correct
84 Correct 24 ms 3456 KB Output is correct
85 Correct 24 ms 3456 KB Output is correct
86 Correct 21 ms 3412 KB Output is correct
87 Correct 22 ms 3412 KB Output is correct
88 Correct 29 ms 3412 KB Output is correct
89 Correct 36 ms 3412 KB Output is correct
90 Correct 35 ms 3412 KB Output is correct
91 Correct 36 ms 3432 KB Output is correct
92 Correct 21 ms 3412 KB Output is correct
93 Correct 192 ms 3412 KB Output is correct
94 Correct 190 ms 3432 KB Output is correct
95 Correct 189 ms 3412 KB Output is correct
96 Correct 190 ms 3448 KB Output is correct
97 Correct 190 ms 3412 KB Output is correct
98 Correct 195 ms 3432 KB Output is correct
99 Correct 194 ms 3436 KB Output is correct
100 Correct 189 ms 3436 KB Output is correct