Submission #934729

# Submission time Handle Problem Language Result Execution time Memory
934729 2024-02-27T21:26:53 Z andrei_iorgulescu Bowling (BOI15_bow) C++14
100 / 100
956 ms 110672 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
 
using namespace std;
 
#define int long long
 
int dp[11][301][32][11][11];
int sdp[11][301][31][11],sumdp[11][301][31];
int n;
char a[25];
int v[15];
 
bool ok(int x,int pos,bool strike,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()
{
    memset(dp,0,sizeof(dp));
    memset(sdp,0,sizeof(sdp));
    memset(sumdp,0,sizeof(sumdp));
    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,true,-1) and ok(h2,2 * n,true,-1) and ok(h3,2 * n + 1,true,-1) and okv(s,n))
                                dp[n][s][h1 + h2 + h3][h1][h2]++;
                        }
                    }
                    else
                    {
                        for (int h3 = 0; h3 <= 10 - h2; h3++)
                        {
                            if (h1 + h2 + h3 <= s and ok(h1,2 * n - 1,true,-1) and ok(h2,2 * n,false,-1) and ok(h3,2 * n + 1,false,h2) and okv(s,n))
                                dp[n][s][h1 + h2 + h3][h1][h2]++;
                        }
                    }
                }
            }
            else
            {
                for (int h2 = 0; h2 <= 10 - h1; h2++)
                {
                    if (h1 + h2 == 10 and ok(h1,2 * n - 1,false,-1) and ok(h2, 2 * n,false,h1))
                    {
                        for (int h3 = 0; h3 <= 10; h3++)
                        {
                            if (ok(h3,2 * n + 1,true,-1) and h1 + h2 + h3 <= s and okv(s,n))
                                dp[n][s][h1 + h2 + h3][h1][h2]++;
                        }
                    }
                    else if (h1 + h2 < 10)
                    {
                        if (h1 + h2 <= s and ok(h1,2 * n - 1,false,-1) and ok(h2,2 * n,false,h1) and ok(-1,2 * n + 1,false,-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,true,-1) and ok(-1,2 * i - 2,false,-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,false,-1) and ok(h2p,2 * i - 2,false,h1p))
                                            dp[i - 1][s - vl][h1p][h2p][f(h1p,h2p,h1,h2)] += dp[i][s][h1][h2][vl];
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }*/
    for (int s = 0; s <= 30 * n; s++)
    {
        for (int h1 = 0; h1 <= 10; h1++)
        {
            for (int h2 = 0; h2 <= 10; h2++)
            {
                for (int vl = 0; vl <= 30; vl++)
                {
                    sumdp[n][s][vl] += dp[n][s][vl][h1][h2];
                    sdp[n][s][vl][h1] += dp[n][s][vl][h1][h2];
                    //if (dp[n][s][h1][h2][vl] != 0)
                      //  cout << s << ' ' << h1 << ' ' << h2 << ' ' << vl << ' ' << dp[n][s][h1][h2][vl] << endl;
                }
            }
        }
    }
    for (int i = n - 1; i >= 1; i--)
    {
        for (int s = 0; s <= 30 * i; s++)
        {
            for (int vlp = 0; vlp <= 30; vlp++)
            {
                for (int h1 = 0; h1 <= 10; h1++)
                {
                    for (int h2 = 0; h2 <= 10; h2++)
                    {
                        if (h1 == 10)
                        {
                            for (int h2p = 0; h2p <= 10; h2p++)
                                if (ok(h1,2 * i - 1,true,-1) and ok(-1,2 * i,true,-1))
                                    dp[i][s][10 + h2 + h2p][h1][h2] += dp[i + 1][s + vlp][vlp][h2][h2p];
                        }
                        else if (h1 + h2 == 10)
                        {
                            for (int h1p = 0; h1p <= 10; h1p++)
                                if (ok(h1,2 * i - 1,false,-1) and ok(h2,2 * i,false,h1))
                                    dp[i][s][10 + h1p][h1][h2] += sdp[i + 1][s + vlp][vlp][h1p];
                        }
                        else if (h1 + h2 < 10)
                        {
                            if (ok(h1,2 * i - 1,false,-1) and ok(h2,2 * i,false,h1))
                                dp[i][s][h1 + h2][h1][h2] += sumdp[i + 1][s + vlp][vlp];
                        }
                    }
                }
            }
        }
        for (int s = 0; s <= 30 * i; s++)
        {
            for (int vl = 0; vl <= 30; vl++)
            {
                for (int h1 = 0; h1 <= 10; h1++)
                {
                    for (int h2 = 0; h2 <= 10; h2++)
                    {
                        if (!okv(s,i))
                            dp[i][s][vl][h1][h2] = 0;
                        //if (dp[i][s][h1][h2][vl] != 0)
                          //  cout << i << ' ' << s << ' ' << h1 << ' ' << h2 << ' ' << vl << ' ' << dp[i][s][h1][h2][vl] << endl;
                        sumdp[i][s][vl] += dp[i][s][vl][h1][h2];
                        sdp[i][s][vl][h1] += dp[i][s][vl][h1][h2];
                    }
                }
            }
        }
    }
    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][s][h1][h2];
            }
        }
    }
    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 334 ms 110312 KB Output is correct
2 Correct 358 ms 110428 KB Output is correct
3 Correct 359 ms 110428 KB Output is correct
4 Correct 377 ms 110192 KB Output is correct
5 Correct 380 ms 110428 KB Output is correct
6 Correct 419 ms 110168 KB Output is correct
7 Correct 457 ms 110424 KB Output is correct
8 Correct 424 ms 110428 KB Output is correct
9 Correct 372 ms 110424 KB Output is correct
10 Correct 423 ms 110172 KB Output is correct
11 Correct 707 ms 110168 KB Output is correct
12 Correct 235 ms 110428 KB Output is correct
13 Correct 53 ms 110424 KB Output is correct
14 Correct 237 ms 110428 KB Output is correct
15 Correct 62 ms 110424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 317 ms 110428 KB Output is correct
2 Correct 424 ms 110172 KB Output is correct
3 Correct 403 ms 110172 KB Output is correct
4 Correct 441 ms 110424 KB Output is correct
5 Correct 452 ms 110168 KB Output is correct
6 Correct 647 ms 110196 KB Output is correct
7 Correct 660 ms 110168 KB Output is correct
8 Correct 664 ms 110424 KB Output is correct
9 Correct 654 ms 110168 KB Output is correct
10 Correct 725 ms 110172 KB Output is correct
11 Correct 734 ms 110168 KB Output is correct
12 Correct 791 ms 110168 KB Output is correct
13 Correct 807 ms 110168 KB Output is correct
14 Correct 822 ms 110172 KB Output is correct
15 Correct 845 ms 110172 KB Output is correct
16 Correct 860 ms 110644 KB Output is correct
17 Correct 843 ms 110428 KB Output is correct
18 Correct 831 ms 110168 KB Output is correct
19 Correct 767 ms 110420 KB Output is correct
20 Correct 793 ms 110168 KB Output is correct
21 Correct 781 ms 110172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 110428 KB Output is correct
2 Correct 441 ms 110428 KB Output is correct
3 Correct 405 ms 110168 KB Output is correct
4 Correct 410 ms 110420 KB Output is correct
5 Correct 373 ms 110168 KB Output is correct
6 Correct 628 ms 110168 KB Output is correct
7 Correct 665 ms 110168 KB Output is correct
8 Correct 599 ms 110424 KB Output is correct
9 Correct 653 ms 110168 KB Output is correct
10 Correct 956 ms 110424 KB Output is correct
11 Correct 851 ms 110168 KB Output is correct
12 Correct 878 ms 110428 KB Output is correct
13 Correct 823 ms 110168 KB Output is correct
14 Correct 818 ms 110424 KB Output is correct
15 Correct 816 ms 110428 KB Output is correct
16 Correct 817 ms 110672 KB Output is correct
17 Correct 830 ms 110172 KB Output is correct
18 Correct 604 ms 110172 KB Output is correct
19 Correct 635 ms 110396 KB Output is correct
20 Correct 585 ms 110428 KB Output is correct
21 Correct 600 ms 110344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 110168 KB Output is correct
2 Correct 404 ms 110408 KB Output is correct
3 Correct 455 ms 110428 KB Output is correct
4 Correct 399 ms 110172 KB Output is correct
5 Correct 392 ms 110172 KB Output is correct
6 Correct 446 ms 110428 KB Output is correct
7 Correct 410 ms 110428 KB Output is correct
8 Correct 411 ms 110168 KB Output is correct
9 Correct 415 ms 110428 KB Output is correct
10 Correct 539 ms 110408 KB Output is correct
11 Correct 519 ms 110412 KB Output is correct
12 Correct 528 ms 110172 KB Output is correct
13 Correct 456 ms 110420 KB Output is correct
14 Correct 678 ms 110172 KB Output is correct
15 Correct 654 ms 110172 KB Output is correct
16 Correct 683 ms 110172 KB Output is correct
17 Correct 680 ms 110408 KB Output is correct
18 Correct 633 ms 110424 KB Output is correct
19 Correct 624 ms 110424 KB Output is correct
20 Correct 627 ms 110172 KB Output is correct
21 Correct 603 ms 110172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 334 ms 110312 KB Output is correct
2 Correct 358 ms 110428 KB Output is correct
3 Correct 359 ms 110428 KB Output is correct
4 Correct 377 ms 110192 KB Output is correct
5 Correct 380 ms 110428 KB Output is correct
6 Correct 419 ms 110168 KB Output is correct
7 Correct 457 ms 110424 KB Output is correct
8 Correct 424 ms 110428 KB Output is correct
9 Correct 372 ms 110424 KB Output is correct
10 Correct 423 ms 110172 KB Output is correct
11 Correct 707 ms 110168 KB Output is correct
12 Correct 235 ms 110428 KB Output is correct
13 Correct 53 ms 110424 KB Output is correct
14 Correct 237 ms 110428 KB Output is correct
15 Correct 62 ms 110424 KB Output is correct
16 Correct 317 ms 110428 KB Output is correct
17 Correct 424 ms 110172 KB Output is correct
18 Correct 403 ms 110172 KB Output is correct
19 Correct 441 ms 110424 KB Output is correct
20 Correct 452 ms 110168 KB Output is correct
21 Correct 647 ms 110196 KB Output is correct
22 Correct 660 ms 110168 KB Output is correct
23 Correct 664 ms 110424 KB Output is correct
24 Correct 654 ms 110168 KB Output is correct
25 Correct 725 ms 110172 KB Output is correct
26 Correct 734 ms 110168 KB Output is correct
27 Correct 791 ms 110168 KB Output is correct
28 Correct 807 ms 110168 KB Output is correct
29 Correct 822 ms 110172 KB Output is correct
30 Correct 845 ms 110172 KB Output is correct
31 Correct 860 ms 110644 KB Output is correct
32 Correct 843 ms 110428 KB Output is correct
33 Correct 831 ms 110168 KB Output is correct
34 Correct 767 ms 110420 KB Output is correct
35 Correct 793 ms 110168 KB Output is correct
36 Correct 781 ms 110172 KB Output is correct
37 Correct 197 ms 110428 KB Output is correct
38 Correct 441 ms 110428 KB Output is correct
39 Correct 405 ms 110168 KB Output is correct
40 Correct 410 ms 110420 KB Output is correct
41 Correct 373 ms 110168 KB Output is correct
42 Correct 628 ms 110168 KB Output is correct
43 Correct 665 ms 110168 KB Output is correct
44 Correct 599 ms 110424 KB Output is correct
45 Correct 653 ms 110168 KB Output is correct
46 Correct 956 ms 110424 KB Output is correct
47 Correct 851 ms 110168 KB Output is correct
48 Correct 878 ms 110428 KB Output is correct
49 Correct 823 ms 110168 KB Output is correct
50 Correct 818 ms 110424 KB Output is correct
51 Correct 816 ms 110428 KB Output is correct
52 Correct 817 ms 110672 KB Output is correct
53 Correct 830 ms 110172 KB Output is correct
54 Correct 604 ms 110172 KB Output is correct
55 Correct 635 ms 110396 KB Output is correct
56 Correct 585 ms 110428 KB Output is correct
57 Correct 600 ms 110344 KB Output is correct
58 Correct 428 ms 110168 KB Output is correct
59 Correct 404 ms 110408 KB Output is correct
60 Correct 455 ms 110428 KB Output is correct
61 Correct 399 ms 110172 KB Output is correct
62 Correct 392 ms 110172 KB Output is correct
63 Correct 446 ms 110428 KB Output is correct
64 Correct 410 ms 110428 KB Output is correct
65 Correct 411 ms 110168 KB Output is correct
66 Correct 415 ms 110428 KB Output is correct
67 Correct 539 ms 110408 KB Output is correct
68 Correct 519 ms 110412 KB Output is correct
69 Correct 528 ms 110172 KB Output is correct
70 Correct 456 ms 110420 KB Output is correct
71 Correct 678 ms 110172 KB Output is correct
72 Correct 654 ms 110172 KB Output is correct
73 Correct 683 ms 110172 KB Output is correct
74 Correct 680 ms 110408 KB Output is correct
75 Correct 633 ms 110424 KB Output is correct
76 Correct 624 ms 110424 KB Output is correct
77 Correct 627 ms 110172 KB Output is correct
78 Correct 603 ms 110172 KB Output is correct
79 Correct 267 ms 110172 KB Output is correct
80 Correct 476 ms 110428 KB Output is correct
81 Correct 435 ms 110424 KB Output is correct
82 Correct 479 ms 110428 KB Output is correct
83 Correct 417 ms 110424 KB Output is correct
84 Correct 732 ms 110428 KB Output is correct
85 Correct 788 ms 110428 KB Output is correct
86 Correct 717 ms 110424 KB Output is correct
87 Correct 733 ms 110172 KB Output is correct
88 Correct 744 ms 110428 KB Output is correct
89 Correct 756 ms 110428 KB Output is correct
90 Correct 758 ms 110232 KB Output is correct
91 Correct 746 ms 110424 KB Output is correct
92 Correct 603 ms 110172 KB Output is correct
93 Correct 870 ms 110428 KB Output is correct
94 Correct 844 ms 110188 KB Output is correct
95 Correct 872 ms 110424 KB Output is correct
96 Correct 837 ms 110168 KB Output is correct
97 Correct 861 ms 110424 KB Output is correct
98 Correct 821 ms 110424 KB Output is correct
99 Correct 840 ms 110168 KB Output is correct
100 Correct 882 ms 110424 KB Output is correct