Submission #230111

# Submission time Handle Problem Language Result Execution time Memory
230111 2020-05-08T12:34:45 Z Kastanda Bowling (BOI15_bow) C++11
100 / 100
117 ms 3456 KB
// Pinkie Pied!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 11;
int n, A[N];
ll dp[N][N][N][279];
char S[N * 2];
int main()
{
    int q;
    scanf("%d", &q);
    for (; q; q --)
    {
        memset(S, 0, sizeof(S));
        memset(A, 0, sizeof(A));
        scanf("%d%s", &n, S);
        for (int i = 1; i <= n; i ++)
            scanf("%d", &A[i]);
        memset(dp, 0, sizeof(dp));
        for (int a = 0; a < 10; a ++)
            for (int b = 0; a + b <= 10; b ++)
                dp[0][a][b][0] = 1;
        for (int b = 0; b <= 10; b ++)
            dp[0][10][b][0] = 1;
        A[0] = -1;
        ll tot = 0;
        for (int i = 0; i <= n - 2; i ++)
        {
            int le = 0, ri = 30 * i;
            if (A[i] != -1)
                le = A[i], ri = A[i];
            for (int a = 0; a < 10; a ++)
                for (int b = 0; a + b < 10; b ++)
                {
                    if (S[i * 2] != '?' && S[i * 2] != '0' + a)
                        continue;
                    if (S[i * 2 + 1] != '?' && S[i * 2 + 1] != '0' + b)
                        continue;
                    for (int c = 0; c <= 10; c ++)
                        for (int d = 0; d <= 10 && (c == 10 || c + d <= 10); d ++)
                            for (int j = le; j <= ri; j ++)
                                dp[i + 1][c][d][j + a + b] += dp[i][a][b][j];
                }
            for (int a = 0; a < 10; a ++)
            {
                int b = 10 - a;
                if (S[i * 2] != '?' && S[i * 2] != '0' + a)
                    continue;
                if (S[i * 2 + 1] != '?' && S[i * 2 + 1] != '/')
                    continue;
                for (int c = 0; c <= 10; c ++)
                    for (int d = 0; d <= 10 && (c == 10 || c + d <= 10); d ++)
                        for (int j = le; j <= ri; j ++)
                            dp[i + 1][c][d][j + 10 + c] += dp[i][a][b][j];
            }
            if (S[i * 2] != '?' && S[i * 2] != 'x')
                continue;
            if (S[i * 2 + 1] != '?' && S[i * 2 + 1] != '-')
                continue;
            int a = 10;
            for (int c = 0; c <= 10; c ++)
                for (int d = 0; d <= 10 && (c == 10 || c + d <= 10); d ++)
                    for (int j = le; j <= ri; j ++)
                        dp[i + 1][c][d][j + 10 + c + d] += dp[i][a][c][j];
        }
        for (int i = n - 1; i <= n - 1; i ++)
        {
            int le = 0, ri = 30 * i;
            if (A[i] != -1)
                le = A[i], ri = A[i];
            for (int a = 0; a < 10; a ++)
                for (int b = 0; a + b < 10; b ++)
                {
                    if (S[i * 2] != '?' && S[i * 2] != '0' + a)
                        continue;
                    if (S[i * 2 + 1] != '?' && S[i * 2 + 1] != '0' + b)
                        continue;
                    if (S[i * 2 + 2] != '?' && S[i * 2 + 2] != '-')
                        continue;
                    for (int j = le; j <= ri; j ++)
                        if (A[i + 1] == -1 || j + a + b == A[i + 1])
                            tot += dp[i][a][b][j];
                }
            for (int a = 0; a < 10; a ++)
            {
                int b = 10 - a;
                if (S[i * 2] != '?' && S[i * 2] != '0' + a)
                    continue;
                if (S[i * 2 + 1] != '?' && S[i * 2 + 1] != '/')
                    continue;

                if (S[i * 2 + 2] == '?' || S[i * 2 + 2] == 'x')
                    for (int j = le; j <= ri; j ++)
                        if (A[i + 1] == -1 || j + a + b + 10 == A[i + 1])
                            tot += dp[i][a][b][j];
                for (int c = 0; c < 10; c ++)
                    if (S[i * 2 + 2] == '?' || S[i * 2 + 2] - '0' == c)
                        for (int j = le; j <= ri; j ++)
                            if (A[i + 1] == -1 || j + a + b + c == A[i + 1])
                                tot += dp[i][a][b][j];
            }
            if (S[i * 2] != '?' && S[i * 2] != 'x')
                continue;
            int a = 10;
            for (int b = 0; b < 10; b ++)
            {
                if (S[i * 2 + 1] != '?' && S[i * 2 + 1] != '0' + b)
                    continue;
                for (int c = 0; b + c < 10; c ++)
                {
                    if (S[i * 2 + 2] != '?' && S[i * 2 + 2] != '0' + c)
                        continue;
                    for (int j = le; j <= ri; j ++)
                        if (A[i + 1] == -1 || j + 10 + b + c == A[i + 1])
                            tot += dp[i][a][b][j];
                }
                if (S[i * 2 + 2] != '?' && S[i * 2 + 2] != '/')
                    continue;
                int c = 10 - b;
                for (int j = le; j <= ri; j ++)
                    if (A[i + 1] == -1 || j + 10 + b + c == A[i + 1])
                        tot += dp[i][a][b][j];
            }
            if (S[i * 2 + 1] != '?' && S[i * 2 + 1] != 'x')
                continue;
            int b = 10;
            for (int c = 0; c < 10; c ++)
            {
                if (S[i * 2 + 2] != '?' && S[i * 2 + 2] != '0' + c)
                    continue;
                for (int j = le; j <= ri; j ++)
                    if (A[i + 1] == -1 || j + 10 + b + c == A[i + 1])
                        tot += dp[i][a][b][j];
            }
            if (S[i * 2 + 2] != '?' && S[i * 2 + 2] != 'x')
                continue;
            int c = 10;
            for (int j = le; j <= ri; j ++)
                if (A[i + 1] == -1 || j + 10 + b + c == A[i + 1])
                    tot += dp[i][a][b][j];
        }
        printf("%lld\n", tot);
    }
    return 0;
}

Compilation message

bow.cpp: In function 'int main()':
bow.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
bow.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%s", &n, S);
         ~~~~~^~~~~~~~~~~~~~~
bow.cpp:19:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &A[i]);
             ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3200 KB Output is correct
2 Correct 9 ms 3200 KB Output is correct
3 Correct 8 ms 3200 KB Output is correct
4 Correct 9 ms 3200 KB Output is correct
5 Correct 8 ms 3200 KB Output is correct
6 Correct 8 ms 3200 KB Output is correct
7 Correct 13 ms 3200 KB Output is correct
8 Correct 14 ms 3328 KB Output is correct
9 Correct 11 ms 3200 KB Output is correct
10 Correct 14 ms 3200 KB Output is correct
11 Correct 15 ms 3200 KB Output is correct
12 Correct 9 ms 3200 KB Output is correct
13 Correct 6 ms 3200 KB Output is correct
14 Correct 8 ms 3200 KB Output is correct
15 Correct 7 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3200 KB Output is correct
2 Correct 17 ms 3200 KB Output is correct
3 Correct 16 ms 3200 KB Output is correct
4 Correct 17 ms 3200 KB Output is correct
5 Correct 20 ms 3200 KB Output is correct
6 Correct 26 ms 3200 KB Output is correct
7 Correct 22 ms 3200 KB Output is correct
8 Correct 22 ms 3200 KB Output is correct
9 Correct 23 ms 3200 KB Output is correct
10 Correct 53 ms 3200 KB Output is correct
11 Correct 54 ms 3200 KB Output is correct
12 Correct 46 ms 3200 KB Output is correct
13 Correct 52 ms 3200 KB Output is correct
14 Correct 31 ms 3200 KB Output is correct
15 Correct 32 ms 3200 KB Output is correct
16 Correct 29 ms 3200 KB Output is correct
17 Correct 33 ms 3200 KB Output is correct
18 Correct 59 ms 3200 KB Output is correct
19 Correct 56 ms 3200 KB Output is correct
20 Correct 63 ms 3200 KB Output is correct
21 Correct 54 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3200 KB Output is correct
2 Correct 11 ms 3200 KB Output is correct
3 Correct 9 ms 3200 KB Output is correct
4 Correct 10 ms 3200 KB Output is correct
5 Correct 10 ms 3200 KB Output is correct
6 Correct 12 ms 3200 KB Output is correct
7 Correct 12 ms 3200 KB Output is correct
8 Correct 12 ms 3200 KB Output is correct
9 Correct 12 ms 3200 KB Output is correct
10 Correct 17 ms 3200 KB Output is correct
11 Correct 12 ms 3200 KB Output is correct
12 Correct 14 ms 3200 KB Output is correct
13 Correct 14 ms 3200 KB Output is correct
14 Correct 17 ms 3200 KB Output is correct
15 Correct 22 ms 3200 KB Output is correct
16 Correct 19 ms 3456 KB Output is correct
17 Correct 21 ms 3200 KB Output is correct
18 Correct 11 ms 3200 KB Output is correct
19 Correct 12 ms 3200 KB Output is correct
20 Correct 12 ms 3200 KB Output is correct
21 Correct 12 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 3276 KB Output is correct
2 Correct 20 ms 3328 KB Output is correct
3 Correct 27 ms 3200 KB Output is correct
4 Correct 19 ms 3200 KB Output is correct
5 Correct 26 ms 3200 KB Output is correct
6 Correct 15 ms 3200 KB Output is correct
7 Correct 16 ms 3200 KB Output is correct
8 Correct 17 ms 3200 KB Output is correct
9 Correct 22 ms 3200 KB Output is correct
10 Correct 46 ms 3320 KB Output is correct
11 Correct 42 ms 3200 KB Output is correct
12 Correct 43 ms 3320 KB Output is correct
13 Correct 40 ms 3200 KB Output is correct
14 Correct 26 ms 3200 KB Output is correct
15 Correct 23 ms 3200 KB Output is correct
16 Correct 28 ms 3200 KB Output is correct
17 Correct 30 ms 3200 KB Output is correct
18 Correct 14 ms 3200 KB Output is correct
19 Correct 17 ms 3200 KB Output is correct
20 Correct 16 ms 3328 KB Output is correct
21 Correct 13 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3200 KB Output is correct
2 Correct 9 ms 3200 KB Output is correct
3 Correct 8 ms 3200 KB Output is correct
4 Correct 9 ms 3200 KB Output is correct
5 Correct 8 ms 3200 KB Output is correct
6 Correct 8 ms 3200 KB Output is correct
7 Correct 13 ms 3200 KB Output is correct
8 Correct 14 ms 3328 KB Output is correct
9 Correct 11 ms 3200 KB Output is correct
10 Correct 14 ms 3200 KB Output is correct
11 Correct 15 ms 3200 KB Output is correct
12 Correct 9 ms 3200 KB Output is correct
13 Correct 6 ms 3200 KB Output is correct
14 Correct 8 ms 3200 KB Output is correct
15 Correct 7 ms 3200 KB Output is correct
16 Correct 20 ms 3200 KB Output is correct
17 Correct 17 ms 3200 KB Output is correct
18 Correct 16 ms 3200 KB Output is correct
19 Correct 17 ms 3200 KB Output is correct
20 Correct 20 ms 3200 KB Output is correct
21 Correct 26 ms 3200 KB Output is correct
22 Correct 22 ms 3200 KB Output is correct
23 Correct 22 ms 3200 KB Output is correct
24 Correct 23 ms 3200 KB Output is correct
25 Correct 53 ms 3200 KB Output is correct
26 Correct 54 ms 3200 KB Output is correct
27 Correct 46 ms 3200 KB Output is correct
28 Correct 52 ms 3200 KB Output is correct
29 Correct 31 ms 3200 KB Output is correct
30 Correct 32 ms 3200 KB Output is correct
31 Correct 29 ms 3200 KB Output is correct
32 Correct 33 ms 3200 KB Output is correct
33 Correct 59 ms 3200 KB Output is correct
34 Correct 56 ms 3200 KB Output is correct
35 Correct 63 ms 3200 KB Output is correct
36 Correct 54 ms 3200 KB Output is correct
37 Correct 15 ms 3200 KB Output is correct
38 Correct 11 ms 3200 KB Output is correct
39 Correct 9 ms 3200 KB Output is correct
40 Correct 10 ms 3200 KB Output is correct
41 Correct 10 ms 3200 KB Output is correct
42 Correct 12 ms 3200 KB Output is correct
43 Correct 12 ms 3200 KB Output is correct
44 Correct 12 ms 3200 KB Output is correct
45 Correct 12 ms 3200 KB Output is correct
46 Correct 17 ms 3200 KB Output is correct
47 Correct 12 ms 3200 KB Output is correct
48 Correct 14 ms 3200 KB Output is correct
49 Correct 14 ms 3200 KB Output is correct
50 Correct 17 ms 3200 KB Output is correct
51 Correct 22 ms 3200 KB Output is correct
52 Correct 19 ms 3456 KB Output is correct
53 Correct 21 ms 3200 KB Output is correct
54 Correct 11 ms 3200 KB Output is correct
55 Correct 12 ms 3200 KB Output is correct
56 Correct 12 ms 3200 KB Output is correct
57 Correct 12 ms 3200 KB Output is correct
58 Correct 30 ms 3276 KB Output is correct
59 Correct 20 ms 3328 KB Output is correct
60 Correct 27 ms 3200 KB Output is correct
61 Correct 19 ms 3200 KB Output is correct
62 Correct 26 ms 3200 KB Output is correct
63 Correct 15 ms 3200 KB Output is correct
64 Correct 16 ms 3200 KB Output is correct
65 Correct 17 ms 3200 KB Output is correct
66 Correct 22 ms 3200 KB Output is correct
67 Correct 46 ms 3320 KB Output is correct
68 Correct 42 ms 3200 KB Output is correct
69 Correct 43 ms 3320 KB Output is correct
70 Correct 40 ms 3200 KB Output is correct
71 Correct 26 ms 3200 KB Output is correct
72 Correct 23 ms 3200 KB Output is correct
73 Correct 28 ms 3200 KB Output is correct
74 Correct 30 ms 3200 KB Output is correct
75 Correct 14 ms 3200 KB Output is correct
76 Correct 17 ms 3200 KB Output is correct
77 Correct 16 ms 3328 KB Output is correct
78 Correct 13 ms 3200 KB Output is correct
79 Correct 27 ms 3200 KB Output is correct
80 Correct 24 ms 3200 KB Output is correct
81 Correct 16 ms 3200 KB Output is correct
82 Correct 19 ms 3200 KB Output is correct
83 Correct 15 ms 3200 KB Output is correct
84 Correct 16 ms 3200 KB Output is correct
85 Correct 15 ms 3200 KB Output is correct
86 Correct 16 ms 3200 KB Output is correct
87 Correct 15 ms 3200 KB Output is correct
88 Correct 42 ms 3200 KB Output is correct
89 Correct 52 ms 3200 KB Output is correct
90 Correct 46 ms 3200 KB Output is correct
91 Correct 47 ms 3320 KB Output is correct
92 Correct 12 ms 3200 KB Output is correct
93 Correct 105 ms 3200 KB Output is correct
94 Correct 104 ms 3200 KB Output is correct
95 Correct 104 ms 3200 KB Output is correct
96 Correct 108 ms 3200 KB Output is correct
97 Correct 107 ms 3200 KB Output is correct
98 Correct 117 ms 3200 KB Output is correct
99 Correct 107 ms 3320 KB Output is correct
100 Correct 102 ms 3200 KB Output is correct