답안 #923532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923532 2024-02-07T11:41:26 Z andrei_iorgulescu Bowling (BOI15_bow) C++14
82 / 100
1000 ms 100952 KB
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")

using namespace std;

#define int long long

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

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 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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 274 ms 100688 KB Output is correct
2 Correct 267 ms 100716 KB Output is correct
3 Correct 274 ms 100700 KB Output is correct
4 Correct 277 ms 100788 KB Output is correct
5 Correct 280 ms 100700 KB Output is correct
6 Correct 295 ms 100764 KB Output is correct
7 Correct 380 ms 100700 KB Output is correct
8 Correct 353 ms 100700 KB Output is correct
9 Correct 326 ms 100700 KB Output is correct
10 Correct 350 ms 100700 KB Output is correct
11 Correct 349 ms 100696 KB Output is correct
12 Correct 242 ms 100700 KB Output is correct
13 Correct 52 ms 100696 KB Output is correct
14 Correct 243 ms 100724 KB Output is correct
15 Correct 61 ms 100700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 218 ms 100752 KB Output is correct
2 Correct 351 ms 100764 KB Output is correct
3 Correct 310 ms 100696 KB Output is correct
4 Correct 298 ms 100696 KB Output is correct
5 Correct 336 ms 100596 KB Output is correct
6 Correct 380 ms 100700 KB Output is correct
7 Correct 449 ms 100700 KB Output is correct
8 Correct 400 ms 100592 KB Output is correct
9 Correct 384 ms 100700 KB Output is correct
10 Correct 572 ms 100696 KB Output is correct
11 Correct 558 ms 100696 KB Output is correct
12 Correct 674 ms 100700 KB Output is correct
13 Correct 619 ms 100700 KB Output is correct
14 Correct 445 ms 100896 KB Output is correct
15 Correct 443 ms 100952 KB Output is correct
16 Correct 382 ms 100696 KB Output is correct
17 Correct 430 ms 100700 KB Output is correct
18 Correct 804 ms 100696 KB Output is correct
19 Correct 799 ms 100700 KB Output is correct
20 Correct 865 ms 100736 KB Output is correct
21 Correct 923 ms 100952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 100696 KB Output is correct
2 Correct 288 ms 100696 KB Output is correct
3 Correct 283 ms 100696 KB Output is correct
4 Correct 282 ms 100700 KB Output is correct
5 Correct 280 ms 100700 KB Output is correct
6 Correct 334 ms 100700 KB Output is correct
7 Correct 344 ms 100620 KB Output is correct
8 Correct 348 ms 100696 KB Output is correct
9 Correct 353 ms 100768 KB Output is correct
10 Correct 370 ms 100700 KB Output is correct
11 Correct 350 ms 100696 KB Output is correct
12 Correct 337 ms 100700 KB Output is correct
13 Correct 349 ms 100696 KB Output is correct
14 Correct 335 ms 100700 KB Output is correct
15 Correct 352 ms 100700 KB Output is correct
16 Correct 340 ms 100852 KB Output is correct
17 Correct 354 ms 100696 KB Output is correct
18 Correct 346 ms 100700 KB Output is correct
19 Correct 349 ms 100700 KB Output is correct
20 Correct 352 ms 100596 KB Output is correct
21 Correct 347 ms 100696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 491 ms 100700 KB Output is correct
2 Correct 371 ms 100696 KB Output is correct
3 Correct 460 ms 100696 KB Output is correct
4 Correct 395 ms 100696 KB Output is correct
5 Correct 342 ms 100696 KB Output is correct
6 Correct 335 ms 100696 KB Output is correct
7 Correct 354 ms 100700 KB Output is correct
8 Correct 352 ms 100700 KB Output is correct
9 Correct 357 ms 100700 KB Output is correct
10 Correct 862 ms 100700 KB Output is correct
11 Correct 807 ms 100700 KB Output is correct
12 Correct 804 ms 100768 KB Output is correct
13 Correct 799 ms 100696 KB Output is correct
14 Correct 517 ms 100696 KB Output is correct
15 Correct 455 ms 100700 KB Output is correct
16 Correct 485 ms 100700 KB Output is correct
17 Correct 487 ms 100696 KB Output is correct
18 Correct 360 ms 100792 KB Output is correct
19 Correct 396 ms 100700 KB Output is correct
20 Correct 393 ms 100696 KB Output is correct
21 Correct 375 ms 100696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 274 ms 100688 KB Output is correct
2 Correct 267 ms 100716 KB Output is correct
3 Correct 274 ms 100700 KB Output is correct
4 Correct 277 ms 100788 KB Output is correct
5 Correct 280 ms 100700 KB Output is correct
6 Correct 295 ms 100764 KB Output is correct
7 Correct 380 ms 100700 KB Output is correct
8 Correct 353 ms 100700 KB Output is correct
9 Correct 326 ms 100700 KB Output is correct
10 Correct 350 ms 100700 KB Output is correct
11 Correct 349 ms 100696 KB Output is correct
12 Correct 242 ms 100700 KB Output is correct
13 Correct 52 ms 100696 KB Output is correct
14 Correct 243 ms 100724 KB Output is correct
15 Correct 61 ms 100700 KB Output is correct
16 Correct 218 ms 100752 KB Output is correct
17 Correct 351 ms 100764 KB Output is correct
18 Correct 310 ms 100696 KB Output is correct
19 Correct 298 ms 100696 KB Output is correct
20 Correct 336 ms 100596 KB Output is correct
21 Correct 380 ms 100700 KB Output is correct
22 Correct 449 ms 100700 KB Output is correct
23 Correct 400 ms 100592 KB Output is correct
24 Correct 384 ms 100700 KB Output is correct
25 Correct 572 ms 100696 KB Output is correct
26 Correct 558 ms 100696 KB Output is correct
27 Correct 674 ms 100700 KB Output is correct
28 Correct 619 ms 100700 KB Output is correct
29 Correct 445 ms 100896 KB Output is correct
30 Correct 443 ms 100952 KB Output is correct
31 Correct 382 ms 100696 KB Output is correct
32 Correct 430 ms 100700 KB Output is correct
33 Correct 804 ms 100696 KB Output is correct
34 Correct 799 ms 100700 KB Output is correct
35 Correct 865 ms 100736 KB Output is correct
36 Correct 923 ms 100952 KB Output is correct
37 Correct 106 ms 100696 KB Output is correct
38 Correct 288 ms 100696 KB Output is correct
39 Correct 283 ms 100696 KB Output is correct
40 Correct 282 ms 100700 KB Output is correct
41 Correct 280 ms 100700 KB Output is correct
42 Correct 334 ms 100700 KB Output is correct
43 Correct 344 ms 100620 KB Output is correct
44 Correct 348 ms 100696 KB Output is correct
45 Correct 353 ms 100768 KB Output is correct
46 Correct 370 ms 100700 KB Output is correct
47 Correct 350 ms 100696 KB Output is correct
48 Correct 337 ms 100700 KB Output is correct
49 Correct 349 ms 100696 KB Output is correct
50 Correct 335 ms 100700 KB Output is correct
51 Correct 352 ms 100700 KB Output is correct
52 Correct 340 ms 100852 KB Output is correct
53 Correct 354 ms 100696 KB Output is correct
54 Correct 346 ms 100700 KB Output is correct
55 Correct 349 ms 100700 KB Output is correct
56 Correct 352 ms 100596 KB Output is correct
57 Correct 347 ms 100696 KB Output is correct
58 Correct 491 ms 100700 KB Output is correct
59 Correct 371 ms 100696 KB Output is correct
60 Correct 460 ms 100696 KB Output is correct
61 Correct 395 ms 100696 KB Output is correct
62 Correct 342 ms 100696 KB Output is correct
63 Correct 335 ms 100696 KB Output is correct
64 Correct 354 ms 100700 KB Output is correct
65 Correct 352 ms 100700 KB Output is correct
66 Correct 357 ms 100700 KB Output is correct
67 Correct 862 ms 100700 KB Output is correct
68 Correct 807 ms 100700 KB Output is correct
69 Correct 804 ms 100768 KB Output is correct
70 Correct 799 ms 100696 KB Output is correct
71 Correct 517 ms 100696 KB Output is correct
72 Correct 455 ms 100700 KB Output is correct
73 Correct 485 ms 100700 KB Output is correct
74 Correct 487 ms 100696 KB Output is correct
75 Correct 360 ms 100792 KB Output is correct
76 Correct 396 ms 100700 KB Output is correct
77 Correct 393 ms 100696 KB Output is correct
78 Correct 375 ms 100696 KB Output is correct
79 Correct 513 ms 100948 KB Output is correct
80 Correct 385 ms 100696 KB Output is correct
81 Correct 367 ms 100700 KB Output is correct
82 Correct 368 ms 100636 KB Output is correct
83 Correct 325 ms 100700 KB Output is correct
84 Correct 344 ms 100696 KB Output is correct
85 Correct 368 ms 100592 KB Output is correct
86 Correct 339 ms 100700 KB Output is correct
87 Correct 353 ms 100700 KB Output is correct
88 Correct 413 ms 100952 KB Output is correct
89 Correct 636 ms 100700 KB Output is correct
90 Correct 601 ms 100772 KB Output is correct
91 Correct 614 ms 100700 KB Output is correct
92 Correct 370 ms 100700 KB Output is correct
93 Correct 386 ms 100700 KB Output is correct
94 Correct 638 ms 100700 KB Output is correct
95 Correct 994 ms 100764 KB Output is correct
96 Execution timed out 1048 ms 100696 KB Time limit exceeded
97 Halted 0 ms 0 KB -