Submission #923537

# Submission time Handle Problem Language Result Execution time Memory
923537 2024-02-07T11:49:01 Z andrei_iorgulescu Bowling (BOI15_bow) C++14
82 / 100
1000 ms 101464 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int dp[11][301][11][11][32];
int n;
char a[25];
int v[15];
int f[11][11][11][11];

bool ok(int x,int pos,int prec)
{
    if (a[pos] == '?')
        return true;
    char cx;
    if (x == -1)
        cx = '-';
    else if (prec == -1)
    {
        if (x >= 0 and x <= 9)
            cx = (char)('0' + x);
        else
            cx = 'x';
    }
    else
    {
        if (x + prec < 10)
            cx = (char)('0' + x);
        else
            cx = '/';
    }
    if (cx == a[pos])
        return true;
    return false;
}

bool okv(int x,int pos)
{
    if (v[pos] == -1)
        return true;
    if (x == v[pos])
        return true;
    return false;
}

int F(int c11,int c12,int c21,int c22)
{
    if (c11 == 10)
    {
        if (c12 != c21)
            return 31;
        return 10 + c21 + c22;
    }
    if (c11 + c12 < 10)
        return c11 + c12;
    else if (c11 + c12 > 10)
        return 31;
    return 10 + c21;
}

void testcase()
{
    for (int i = 0; i < 11; i++)
        for (int ii = 0; ii < 11; ii++)
            for (int j = 0; j < 11; j++)
                for (int jj = 0; jj < 11; jj++)
                    f[i][ii][j][jj] = F(i,ii,j,jj);
    for (int i = 0; i < 11; i++)
        for (int j = 0; j < 301; j++)
            for (int ii = 0; ii < 11; ii++)
                for (int jj = 0; jj < 11; jj++)
                    for (int kkk = 0; kkk < 32; kkk++)
                        dp[i][j][ii][jj][kkk] = 0;
    cin >> n;
    for (int i = 1; i <= 2 * n + 1; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> v[i];
    for (int s = 0; s <= 30 * n; s++)
    {
        for (int h1 = 0; h1 <= 10; h1++)
        {
            if (h1 == 10)
            {
                for (int h2 = 0; h2 <= 10; h2++)
                {
                    if (h2 == 10)
                    {
                        for (int h3 = 0; h3 <= 10; h3++)
                        {
                            if (h1 + h2 + h3 <= s and ok(h1,2 * n - 1,-1) and ok(h2,2 * n,-1) and ok(h3,2 * n + 1,-1) and okv(s,n))
                                dp[n][s][h1][h2][h1 + h2 + h3]++;
                        }
                    }
                    else
                    {
                        for (int h3 = 0; h3 <= 10 - h2; h3++)
                        {
                            if (h1 + h2 + h3 <= s and ok(h1,2 * n - 1,-1) and ok(h2,2 * n,-1) and ok(h3,2 * n + 1,h2) and okv(s,n))
                                dp[n][s][h1][h2][h1 + h2 + h3]++;
                        }
                    }
                }
            }
            else
            {
                for (int h2 = 0; h2 <= 10 - h1; h2++)
                {
                    if (h1 + h2 == 10 and ok(h1,2 * n - 1,-1) and ok(h2, 2 * n,h1))
                    {
                        for (int h3 = 0; h3 <= 10; h3++)
                        {
                            if (ok(h3,2 * n + 1,-1) and h1 + h2 + h3 <= s and okv(s,n))
                                dp[n][s][h1][h2][h1 + h2 + h3]++;
                        }
                    }
                    else if (h1 + h2 < 10)
                    {
                        if (h1 + h2 <= s and ok(h1,2 * n - 1,-1) and ok(h2,2 * n,h1) and ok(-1,2 * n + 1,-1) and okv(s,n))
                            dp[n][s][h1][h2][h1 + h2]++;
                    }
                }
            }
        }
    }
    for (int i = n; i > 1; i--)
    {
        for (int s = 0; s <= 30 * i; s++)
        {
            for (int h1 = 0; h1 <= 10; h1++)
            {
                for (int h2 = 0; h2 <= 10; h2++)
                {
                    for (int vl = 0; vl <= min(30ll,s); vl++)
                    {
                        if (dp[i][s][h1][h2][vl] == 0)
                            continue;
                        if (!okv(s - vl,i - 1))
                            continue;
                        //cout << i << ' ' << s << ' ' << h1 << ' ' << h2 << ' ' << vl << endl;
                        for (int h1p = 0; h1p <= 10; h1p++)
                        {
                            for (int h2p = 0; h2p <= 10; h2p++)
                            {
                                if (f[h1p][h2p][h1][h2] <= s - vl)
                                {
                                    if (h1p == 10 and ok(10,2 * i - 3,-1) and ok(-1,2 * i - 2,-1))
                                        dp[i - 1][s - vl][h1p][h2p][f[h1p][h2p][h1][h2]] += dp[i][s][h1][h2][vl];
                                    else if (h1p != 10)
                                    {
                                        if (h1p + h2p <= 10 and ok(h1p,2 * i - 3,-1) and ok(h2p,2 * i - 2,h1p))
                                            dp[i - 1][s - vl][h1p][h2p][f[h1p][h2p][h1][h2]] += dp[i][s][h1][h2][vl];
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int s = 0; s <= 30; s++)
    {
        for (int h1 = 0; h1 <= 10; h1++)
        {
            for (int h2 = 0; h2 <= 10; h2++)
            {
                //if (dp[1][s][h1][h2][s] != 0)
                  //  cout << s << ' ' << h1 << ' ' << h2 << ' ' << dp[1][s][h1][h2][s] << endl;
                ans += dp[1][s][h1][h2][s];
            }
        }
    }
    cout << ans << '\n';
}

signed main()
{
    int tc;
    cin >> tc;
    while (tc--)
        testcase();
    return 0;
}

/**
hoping for a miracle
**/

/*
1
2
?????
10 -1
*/
# Verdict Execution time Memory Grader output
1 Correct 241 ms 100828 KB Output is correct
2 Correct 237 ms 100696 KB Output is correct
3 Correct 240 ms 100952 KB Output is correct
4 Correct 245 ms 100700 KB Output is correct
5 Correct 247 ms 100696 KB Output is correct
6 Correct 267 ms 100876 KB Output is correct
7 Correct 336 ms 100852 KB Output is correct
8 Correct 323 ms 100696 KB Output is correct
9 Correct 282 ms 100700 KB Output is correct
10 Correct 308 ms 100696 KB Output is correct
11 Correct 324 ms 100700 KB Output is correct
12 Correct 209 ms 100696 KB Output is correct
13 Correct 47 ms 100696 KB Output is correct
14 Correct 207 ms 100696 KB Output is correct
15 Correct 56 ms 100700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 191 ms 100696 KB Output is correct
2 Correct 299 ms 100876 KB Output is correct
3 Correct 291 ms 100696 KB Output is correct
4 Correct 277 ms 100784 KB Output is correct
5 Correct 303 ms 100900 KB Output is correct
6 Correct 355 ms 100700 KB Output is correct
7 Correct 400 ms 100876 KB Output is correct
8 Correct 392 ms 100896 KB Output is correct
9 Correct 347 ms 100700 KB Output is correct
10 Correct 529 ms 100888 KB Output is correct
11 Correct 489 ms 100700 KB Output is correct
12 Correct 589 ms 100700 KB Output is correct
13 Correct 559 ms 100952 KB Output is correct
14 Correct 418 ms 100752 KB Output is correct
15 Correct 400 ms 100696 KB Output is correct
16 Correct 346 ms 100700 KB Output is correct
17 Correct 375 ms 100696 KB Output is correct
18 Correct 701 ms 100880 KB Output is correct
19 Correct 697 ms 100696 KB Output is correct
20 Correct 751 ms 100700 KB Output is correct
21 Correct 782 ms 100700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 100700 KB Output is correct
2 Correct 267 ms 100696 KB Output is correct
3 Correct 255 ms 100700 KB Output is correct
4 Correct 248 ms 100700 KB Output is correct
5 Correct 241 ms 100700 KB Output is correct
6 Correct 329 ms 100696 KB Output is correct
7 Correct 310 ms 100696 KB Output is correct
8 Correct 311 ms 100896 KB Output is correct
9 Correct 313 ms 100696 KB Output is correct
10 Correct 327 ms 100696 KB Output is correct
11 Correct 318 ms 100700 KB Output is correct
12 Correct 330 ms 100880 KB Output is correct
13 Correct 324 ms 100696 KB Output is correct
14 Correct 340 ms 100880 KB Output is correct
15 Correct 316 ms 100812 KB Output is correct
16 Correct 329 ms 100696 KB Output is correct
17 Correct 333 ms 100804 KB Output is correct
18 Correct 318 ms 100952 KB Output is correct
19 Correct 324 ms 100696 KB Output is correct
20 Correct 324 ms 100696 KB Output is correct
21 Correct 326 ms 101464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 100700 KB Output is correct
2 Correct 318 ms 101124 KB Output is correct
3 Correct 394 ms 100700 KB Output is correct
4 Correct 332 ms 100696 KB Output is correct
5 Correct 297 ms 100700 KB Output is correct
6 Correct 290 ms 100700 KB Output is correct
7 Correct 298 ms 100700 KB Output is correct
8 Correct 296 ms 100700 KB Output is correct
9 Correct 300 ms 100696 KB Output is correct
10 Correct 729 ms 100696 KB Output is correct
11 Correct 667 ms 100700 KB Output is correct
12 Correct 677 ms 100872 KB Output is correct
13 Correct 656 ms 100852 KB Output is correct
14 Correct 471 ms 100952 KB Output is correct
15 Correct 407 ms 100696 KB Output is correct
16 Correct 425 ms 100700 KB Output is correct
17 Correct 440 ms 100696 KB Output is correct
18 Correct 333 ms 100696 KB Output is correct
19 Correct 371 ms 100904 KB Output is correct
20 Correct 365 ms 100700 KB Output is correct
21 Correct 344 ms 100696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 100828 KB Output is correct
2 Correct 237 ms 100696 KB Output is correct
3 Correct 240 ms 100952 KB Output is correct
4 Correct 245 ms 100700 KB Output is correct
5 Correct 247 ms 100696 KB Output is correct
6 Correct 267 ms 100876 KB Output is correct
7 Correct 336 ms 100852 KB Output is correct
8 Correct 323 ms 100696 KB Output is correct
9 Correct 282 ms 100700 KB Output is correct
10 Correct 308 ms 100696 KB Output is correct
11 Correct 324 ms 100700 KB Output is correct
12 Correct 209 ms 100696 KB Output is correct
13 Correct 47 ms 100696 KB Output is correct
14 Correct 207 ms 100696 KB Output is correct
15 Correct 56 ms 100700 KB Output is correct
16 Correct 191 ms 100696 KB Output is correct
17 Correct 299 ms 100876 KB Output is correct
18 Correct 291 ms 100696 KB Output is correct
19 Correct 277 ms 100784 KB Output is correct
20 Correct 303 ms 100900 KB Output is correct
21 Correct 355 ms 100700 KB Output is correct
22 Correct 400 ms 100876 KB Output is correct
23 Correct 392 ms 100896 KB Output is correct
24 Correct 347 ms 100700 KB Output is correct
25 Correct 529 ms 100888 KB Output is correct
26 Correct 489 ms 100700 KB Output is correct
27 Correct 589 ms 100700 KB Output is correct
28 Correct 559 ms 100952 KB Output is correct
29 Correct 418 ms 100752 KB Output is correct
30 Correct 400 ms 100696 KB Output is correct
31 Correct 346 ms 100700 KB Output is correct
32 Correct 375 ms 100696 KB Output is correct
33 Correct 701 ms 100880 KB Output is correct
34 Correct 697 ms 100696 KB Output is correct
35 Correct 751 ms 100700 KB Output is correct
36 Correct 782 ms 100700 KB Output is correct
37 Correct 95 ms 100700 KB Output is correct
38 Correct 267 ms 100696 KB Output is correct
39 Correct 255 ms 100700 KB Output is correct
40 Correct 248 ms 100700 KB Output is correct
41 Correct 241 ms 100700 KB Output is correct
42 Correct 329 ms 100696 KB Output is correct
43 Correct 310 ms 100696 KB Output is correct
44 Correct 311 ms 100896 KB Output is correct
45 Correct 313 ms 100696 KB Output is correct
46 Correct 327 ms 100696 KB Output is correct
47 Correct 318 ms 100700 KB Output is correct
48 Correct 330 ms 100880 KB Output is correct
49 Correct 324 ms 100696 KB Output is correct
50 Correct 340 ms 100880 KB Output is correct
51 Correct 316 ms 100812 KB Output is correct
52 Correct 329 ms 100696 KB Output is correct
53 Correct 333 ms 100804 KB Output is correct
54 Correct 318 ms 100952 KB Output is correct
55 Correct 324 ms 100696 KB Output is correct
56 Correct 324 ms 100696 KB Output is correct
57 Correct 326 ms 101464 KB Output is correct
58 Correct 407 ms 100700 KB Output is correct
59 Correct 318 ms 101124 KB Output is correct
60 Correct 394 ms 100700 KB Output is correct
61 Correct 332 ms 100696 KB Output is correct
62 Correct 297 ms 100700 KB Output is correct
63 Correct 290 ms 100700 KB Output is correct
64 Correct 298 ms 100700 KB Output is correct
65 Correct 296 ms 100700 KB Output is correct
66 Correct 300 ms 100696 KB Output is correct
67 Correct 729 ms 100696 KB Output is correct
68 Correct 667 ms 100700 KB Output is correct
69 Correct 677 ms 100872 KB Output is correct
70 Correct 656 ms 100852 KB Output is correct
71 Correct 471 ms 100952 KB Output is correct
72 Correct 407 ms 100696 KB Output is correct
73 Correct 425 ms 100700 KB Output is correct
74 Correct 440 ms 100696 KB Output is correct
75 Correct 333 ms 100696 KB Output is correct
76 Correct 371 ms 100904 KB Output is correct
77 Correct 365 ms 100700 KB Output is correct
78 Correct 344 ms 100696 KB Output is correct
79 Correct 420 ms 100700 KB Output is correct
80 Correct 325 ms 100696 KB Output is correct
81 Correct 317 ms 100700 KB Output is correct
82 Correct 324 ms 100696 KB Output is correct
83 Correct 278 ms 100700 KB Output is correct
84 Correct 318 ms 100696 KB Output is correct
85 Correct 332 ms 100696 KB Output is correct
86 Correct 320 ms 100696 KB Output is correct
87 Correct 315 ms 100728 KB Output is correct
88 Correct 367 ms 100696 KB Output is correct
89 Correct 537 ms 100700 KB Output is correct
90 Correct 522 ms 100700 KB Output is correct
91 Correct 545 ms 100700 KB Output is correct
92 Correct 344 ms 100700 KB Output is correct
93 Correct 340 ms 100700 KB Output is correct
94 Correct 541 ms 100828 KB Output is correct
95 Correct 795 ms 100700 KB Output is correct
96 Execution timed out 1016 ms 100700 KB Time limit exceeded
97 Halted 0 ms 0 KB -