Submission #727170

# Submission time Handle Problem Language Result Execution time Memory
727170 2023-04-20T06:48:52 Z stasio6 Bowling (BOI15_bow) C++14
100 / 100
30 ms 596 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FI first
#define ND second
#define maxeq(x, y) (x) = max((x), (y))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int maxFrameScore[11] = {0, 10, 30, 60, 90, 120, 150, 180, 210, 240, 300};
int score[20];

ll dp[15][500][4];
string game;

bool cmp(int i, char c1, char c2) {
    return (game[2*(i-1)] == '?' || game[2*(i-1)] == c1) && (game[2*(i-1)+1] == '?' || game[2*(i-1)+1] == c2);
}

bool scorecmp(int i, int s) {
    return score[i] == -1 || score[i] == s;
}

void fun() {
    int n;
    cin >> n;
    cin >> game;
    game += "?";
    for (int i = 1; i <= n; i++) {
        cin >> score[i];
    }
    for (int i = 0; i < 15; i++)
        for (int s = 0; s < 500; s++)
            for (int st = 0; st < 4; st++)
                dp[i][s][st]= 0;
    dp[0][0][0] = 1;
    for (int i = 1; i < n; i++) {
        for (int s = 0; s <= maxFrameScore[i]; s++) {
            // Strike
            if (cmp(i, 'x', '-')) {
                // no strikes
                if (s >= 10 && scorecmp(i-1, s-10))
                    dp[i][s][2] += dp[i - 1][s - 10][0];
                // spare
                if (s >= 20 && scorecmp(i-1, s-10))
                    dp[i][s][2] += dp[i - 1][s - 20][1];
                // strike
                if (s >= 20)
                    dp[i][s][3] += dp[i - 1][s - 20][2];
                // double strike
                if (s >= 30 && i > 2 && scorecmp(i - 2, s - 30))
                    dp[i][s][3] += dp[i - 1][s - 30][3];
            }
            for (int r1 = 0; r1 < 10; r1++) {
                for (int r2 = 0; r2 <= 10 - r1; r2++) {
                    int spare = 0;
                    if (r1 + r2 == 10) {
                        if (!cmp(i, '0' + r1, '/'))
                            continue;
                        spare = 1;
                    } else {
                        if (!cmp(i, '0' + r1, '0' + r2))
                            continue;
                    }
                    // no strikes
                    if (s >= r1 + r2 && scorecmp(i-1, s-r1-r2))
                        dp[i][s][spare] += dp[i - 1][s - r1 - r2][0];
                    // spare
                    if (s >= 2*r1 + r2 && scorecmp(i-1, s-r1-r2))
                        dp[i][s][spare] += dp[i - 1][s - 2*r1-r2][1];
                    // strike
                    if (s >= 2*(r1+r2) && scorecmp(i-1, s-r1-r2))
                        dp[i][s][spare] += dp[i - 1][s - 2*(r1+r2)][2];
                    // double strike
                    if (s >= 3*r1+2*r2 && i > 2 && scorecmp(i - 2, s - 10 - 2*(r1+r2)) && scorecmp(i-1, s-r1-r2))
                        dp[i][s][spare] += dp[i - 1][s - 3*r1-2*r2][3];
                }
            }
        }
    }
    // Ostatnia runda
    ll ile = 0;
    for (int s = 0; s <= 400; s++) {
        if (!scorecmp(n, s))
            continue;
        // 3 striki lub 2 striki cos
        for (int t = 0; t <= 10; t++) {
            if (!cmp(n, 'x', 'x') || !cmp(n+1, t == 10 ? 'x' : '0'+t, '?'))
                continue;
            // no strikes
            if (s >= 20+t && scorecmp(n-1, s-20-t))
                ile += dp[n - 1][s - 20 - t][0];
            // spare
            if (s >= 30+t && scorecmp(n-1, s-20-t))
                ile += dp[n - 1][s - 30 - t][1];
            // strike
            if (s >= 40+t && scorecmp(n-1, s - 20-t))
                ile += dp[n - 1][s - 40 - t][2];
            // double strike
            if (s >= 50+t && n > 2 && scorecmp(n-1, s - 20 - t) && scorecmp(n-2, s - 50 - t))
                ile += dp[n - 1][s - 50 - t][3];
        }
        // strike cos
        for (int p = 0; p < 10; p++) {
            for (int d = 0; d <= 10 - p; d++) {
                if (!cmp(n, 'x', '0'+p) || !cmp(n+1, p+d == 10 ? '/' : '0'+d, '?'))
                    continue;
                // no strikes
                if (s >= 10+p+d && scorecmp(n-1, s-10-p-d))
                    ile += dp[n - 1][s - 10 - p - d][0];
                // spare
                if (s >= 20+p+d && scorecmp(n-1, s-10-p-d))
                    ile += dp[n - 1][s - 20 - p - d][1];
                // strike
                if (s >= 20+2*p+d && scorecmp(n-1, s - 10 - p - d))
                    ile += dp[n - 1][s - 20 - 2*p-d][2];
                // double strike
                if (s >= 30+2*p+d && n > 2 && scorecmp(n-1, s - 10 - p - d) && scorecmp(n-2, s - 30 - 2*p - d))
                    ile += dp[n - 1][s - 30 - 2*p-d][3];
            }
        }
        // spare cos
        for (int p = 0; p < 10; p++) {
            for (int d = 0; d <= 10; d++) {
                if (!cmp(n, '0'+p, '/') || !cmp(n+1, d == 10 ? 'x' : '0'+d, '?'))
                    continue;
                // no strikes
                if (s >= 10+d && scorecmp(n-1, s-10-d))
                    ile += dp[n - 1][s - 10 - d][0];
                // spare
                if (s >= 10+p+d && scorecmp(n-1, s-10-d))
                    ile += dp[n - 1][s - 10 - p - d][1];
                // strike
                if (s >= 20+d && scorecmp(n-1, s - 10 - d))
                    ile += dp[n - 1][s - 20 -d][2];
                // double strike
                if (s >= 20+p+d && n > 2 && scorecmp(n-1, s - 10 - d) && scorecmp(n-2, s - 30 - d))
                    ile += dp[n - 1][s - 20 - p-d][3];
            }
        }
        // cos
        for (int p = 0; p < 10; p++) {
            for (int d = 0; d < 10-p; d++) {
                if (!cmp(n, '0'+p, '0'+d) || !cmp(n+1, '-', '?'))
                    continue;
                // no strikes
                if (s >= p+d && scorecmp(n-1, s-p-d))
                    ile += dp[n - 1][s - p - d][0];
                // spare
                if (s >= 2*p+d && scorecmp(n-1, s-p-d))
                    ile += dp[n - 1][s - 2*p - d][1];
                // strike
                if (s >= 2*(p+d) && scorecmp(n-1, s - p - d))
                    ile += dp[n - 1][s - 2*(p+d)][2];
                // double strike
                if (s >= 3*p+2*d && n > 2 && scorecmp(n-1, s - p - d) && scorecmp(n-2, s - 10 - 2*p-2*d))
                    ile += dp[n - 1][s - 3*p-2*d][3];
            }
        }
    }
    cout << ile << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) fun();
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 4 ms 460 KB Output is correct
3 Correct 2 ms 456 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 7 ms 468 KB Output is correct
8 Correct 8 ms 468 KB Output is correct
9 Correct 6 ms 560 KB Output is correct
10 Correct 8 ms 468 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 7 ms 468 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 7 ms 468 KB Output is correct
5 Correct 9 ms 552 KB Output is correct
6 Correct 11 ms 468 KB Output is correct
7 Correct 12 ms 564 KB Output is correct
8 Correct 12 ms 468 KB Output is correct
9 Correct 12 ms 556 KB Output is correct
10 Correct 24 ms 468 KB Output is correct
11 Correct 21 ms 468 KB Output is correct
12 Correct 24 ms 468 KB Output is correct
13 Correct 23 ms 468 KB Output is correct
14 Correct 21 ms 468 KB Output is correct
15 Correct 19 ms 456 KB Output is correct
16 Correct 21 ms 548 KB Output is correct
17 Correct 17 ms 468 KB Output is correct
18 Correct 23 ms 564 KB Output is correct
19 Correct 26 ms 468 KB Output is correct
20 Correct 25 ms 468 KB Output is correct
21 Correct 24 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 7 ms 588 KB Output is correct
3 Correct 5 ms 560 KB Output is correct
4 Correct 5 ms 552 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 8 ms 468 KB Output is correct
7 Correct 8 ms 560 KB Output is correct
8 Correct 7 ms 464 KB Output is correct
9 Correct 8 ms 468 KB Output is correct
10 Correct 13 ms 552 KB Output is correct
11 Correct 12 ms 468 KB Output is correct
12 Correct 12 ms 468 KB Output is correct
13 Correct 12 ms 560 KB Output is correct
14 Correct 14 ms 468 KB Output is correct
15 Correct 14 ms 468 KB Output is correct
16 Correct 15 ms 540 KB Output is correct
17 Correct 16 ms 560 KB Output is correct
18 Correct 7 ms 460 KB Output is correct
19 Correct 6 ms 468 KB Output is correct
20 Correct 7 ms 460 KB Output is correct
21 Correct 7 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 468 KB Output is correct
2 Correct 7 ms 468 KB Output is correct
3 Correct 9 ms 468 KB Output is correct
4 Correct 7 ms 560 KB Output is correct
5 Correct 7 ms 464 KB Output is correct
6 Correct 9 ms 468 KB Output is correct
7 Correct 9 ms 460 KB Output is correct
8 Correct 8 ms 460 KB Output is correct
9 Correct 8 ms 456 KB Output is correct
10 Correct 15 ms 468 KB Output is correct
11 Correct 13 ms 596 KB Output is correct
12 Correct 14 ms 560 KB Output is correct
13 Correct 12 ms 468 KB Output is correct
14 Correct 13 ms 468 KB Output is correct
15 Correct 11 ms 468 KB Output is correct
16 Correct 11 ms 468 KB Output is correct
17 Correct 14 ms 468 KB Output is correct
18 Correct 8 ms 468 KB Output is correct
19 Correct 11 ms 560 KB Output is correct
20 Correct 8 ms 468 KB Output is correct
21 Correct 8 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 4 ms 460 KB Output is correct
3 Correct 2 ms 456 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 7 ms 468 KB Output is correct
8 Correct 8 ms 468 KB Output is correct
9 Correct 6 ms 560 KB Output is correct
10 Correct 8 ms 468 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 6 ms 468 KB Output is correct
17 Correct 7 ms 468 KB Output is correct
18 Correct 6 ms 468 KB Output is correct
19 Correct 7 ms 468 KB Output is correct
20 Correct 9 ms 552 KB Output is correct
21 Correct 11 ms 468 KB Output is correct
22 Correct 12 ms 564 KB Output is correct
23 Correct 12 ms 468 KB Output is correct
24 Correct 12 ms 556 KB Output is correct
25 Correct 24 ms 468 KB Output is correct
26 Correct 21 ms 468 KB Output is correct
27 Correct 24 ms 468 KB Output is correct
28 Correct 23 ms 468 KB Output is correct
29 Correct 21 ms 468 KB Output is correct
30 Correct 19 ms 456 KB Output is correct
31 Correct 21 ms 548 KB Output is correct
32 Correct 17 ms 468 KB Output is correct
33 Correct 23 ms 564 KB Output is correct
34 Correct 26 ms 468 KB Output is correct
35 Correct 25 ms 468 KB Output is correct
36 Correct 24 ms 468 KB Output is correct
37 Correct 4 ms 468 KB Output is correct
38 Correct 7 ms 588 KB Output is correct
39 Correct 5 ms 560 KB Output is correct
40 Correct 5 ms 552 KB Output is correct
41 Correct 4 ms 468 KB Output is correct
42 Correct 8 ms 468 KB Output is correct
43 Correct 8 ms 560 KB Output is correct
44 Correct 7 ms 464 KB Output is correct
45 Correct 8 ms 468 KB Output is correct
46 Correct 13 ms 552 KB Output is correct
47 Correct 12 ms 468 KB Output is correct
48 Correct 12 ms 468 KB Output is correct
49 Correct 12 ms 560 KB Output is correct
50 Correct 14 ms 468 KB Output is correct
51 Correct 14 ms 468 KB Output is correct
52 Correct 15 ms 540 KB Output is correct
53 Correct 16 ms 560 KB Output is correct
54 Correct 7 ms 460 KB Output is correct
55 Correct 6 ms 468 KB Output is correct
56 Correct 7 ms 460 KB Output is correct
57 Correct 7 ms 564 KB Output is correct
58 Correct 11 ms 468 KB Output is correct
59 Correct 7 ms 468 KB Output is correct
60 Correct 9 ms 468 KB Output is correct
61 Correct 7 ms 560 KB Output is correct
62 Correct 7 ms 464 KB Output is correct
63 Correct 9 ms 468 KB Output is correct
64 Correct 9 ms 460 KB Output is correct
65 Correct 8 ms 460 KB Output is correct
66 Correct 8 ms 456 KB Output is correct
67 Correct 15 ms 468 KB Output is correct
68 Correct 13 ms 596 KB Output is correct
69 Correct 14 ms 560 KB Output is correct
70 Correct 12 ms 468 KB Output is correct
71 Correct 13 ms 468 KB Output is correct
72 Correct 11 ms 468 KB Output is correct
73 Correct 11 ms 468 KB Output is correct
74 Correct 14 ms 468 KB Output is correct
75 Correct 8 ms 468 KB Output is correct
76 Correct 11 ms 560 KB Output is correct
77 Correct 8 ms 468 KB Output is correct
78 Correct 8 ms 468 KB Output is correct
79 Correct 10 ms 556 KB Output is correct
80 Correct 12 ms 560 KB Output is correct
81 Correct 10 ms 556 KB Output is correct
82 Correct 9 ms 560 KB Output is correct
83 Correct 10 ms 564 KB Output is correct
84 Correct 13 ms 468 KB Output is correct
85 Correct 12 ms 456 KB Output is correct
86 Correct 11 ms 460 KB Output is correct
87 Correct 10 ms 468 KB Output is correct
88 Correct 19 ms 468 KB Output is correct
89 Correct 20 ms 468 KB Output is correct
90 Correct 20 ms 468 KB Output is correct
91 Correct 20 ms 556 KB Output is correct
92 Correct 8 ms 468 KB Output is correct
93 Correct 29 ms 468 KB Output is correct
94 Correct 28 ms 468 KB Output is correct
95 Correct 30 ms 540 KB Output is correct
96 Correct 30 ms 588 KB Output is correct
97 Correct 28 ms 460 KB Output is correct
98 Correct 28 ms 540 KB Output is correct
99 Correct 28 ms 468 KB Output is correct
100 Correct 28 ms 544 KB Output is correct