Submission #956778

# Submission time Handle Problem Language Result Execution time Memory
956778 2024-04-02T13:01:07 Z GrindMachine Bowling (BOI15_bow) C++17
82 / 100
1000 ms 1688 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*



*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

void solve(int test_case)
{
    ll n; cin >> n;
    string s; cin >> s;
    s = "$" + s;
    vector<ll> a(n+5);
    rep1(i,n) cin >> a[i];

    ll m = 30*n+5;
    ll dp1[m+5][15][15], dp2[m+5][15][15];
    memset(dp1,0,sizeof dp1);
    memset(dp2,0,sizeof dp2);
    if(a[n] != -1){
        dp1[a[n]][0][0] = 1;
    }
    else{
        rep(j,m+1){
            dp1[j][0][0] = 1;
        }
    }

    ll ptr = 2*n+1;

    auto ok = [&](string put, string pat){
        assert(sz(put) == sz(pat));
        rep(i,sz(put)){
            if(pat[i] == '?') conts;
            if(put[i] != pat[i]) return false; 
        }

        return true;
    };

    // final stage
    {
        string pat = "";
        rep(iter,3){
            pat.pb(s[ptr--]);
        }

        reverse(all(pat));
        vector<array<ll,3>> possible;

        // xxx
        if(ok("xxx",pat)){
            ll score = 30;
            possible.pb({score,10,10});
        }

        // xxA
        rep(A,10){
            string curr = "xx"+to_string(A);
            if(ok(curr,pat)){
                ll score = 20+A;
                possible.pb({score,10,10});
            }
        }

        // xA/
        rep(A,10){
            string curr = "x"+to_string(A)+"/";
            if(ok(curr,pat)){
                ll score = 20;
                possible.pb({score,10,A});
            }
        }

        // xAB
        rep(A,10){
            rep(B,10){
                if(A+B >= 10) break;
                string curr = "x"+to_string(A)+to_string(B);
                if(ok(curr,pat)){
                    ll score = 10+A+B;
                    possible.pb({score,10,A});
                }
            }
        }

        // A/x
        rep(A,10){
            string curr = to_string(A)+"/x";
            if(ok(curr,pat)){
                ll score = 20;
                possible.pb({score,A,10-A});
            }
        }

        // A/B
        rep(A,10){
            rep(B,10){
                string curr = to_string(A)+"/"+to_string(B);
                if(ok(curr,pat)){
                    ll score = 10+B;
                    possible.pb({score,A,10-A});
                }
            }
        }

        // AB-
        rep(A,10){
            rep(B,10){
                if(A+B >= 10) break;
                string curr = to_string(A)+to_string(B)+"-";
                if(ok(curr,pat)){
                    ll score = A+B;
                    possible.pb({score,A,B});
                }
            }
        }

        rep(j,m+1){
            if(!dp1[j][0][0]) conts;
            for(auto [score,x,y] : possible){
                if(j >= score){
                    dp2[j-score][x][y] += dp1[j][0][0];
                }
            }
        }
    }

    rev(i,n-1,1){
        string pat = "";
        rep(iter,2){
            pat.pb(s[ptr--]);
        }

        reverse(all(pat));

        rep(j,m+1){
            rep(x,11){
                rep(y,11){
                    if(a[i] != -1 and a[i] != j){
                        dp1[j][x][y] = 0;
                    }
                    else{
                        dp1[j][x][y] = dp2[j][x][y];
                    }

                    dp2[j][x][y] = 0;
                }
            }
        }

        rep(x,11){
            rep(y,11){
                vector<array<ll,3>> possible;

                // x-
                if(ok("x-",pat)){
                    ll score = 10+x+y;
                    possible.pb({score,10,x});
                }

                // A/
                rep(A,10){
                    string curr = to_string(A)+"/";
                    if(ok(curr,pat)){
                        ll score = 10+x;
                        possible.pb({score,A,10-A});
                    }
                }

                // AB
                rep(A,10){
                    rep(B,10){
                        if(A+B >= 10) conts;
                        string curr = to_string(A)+to_string(B);
                        if(ok(curr,pat)){
                            ll score = A+B;
                            possible.pb({score,A,B});
                        }
                    }
                }

                rep(j,m+1){
                    for(auto [score,x2,y2] : possible){
                        if(j >= score){
                            dp2[j-score][x2][y2] += dp1[j][x][y];
                        }
                    }
                }
            }
        }
    }

    ll ans = 0;
    rep(x,11){
        rep(y,11){
            ans += dp2[0][x][y];
        }
    }

    cout << ans << endl;
}

int main()
{
    fastio;

    int t = 1;
    cin >> t;

    rep1(i, t) {
        solve(i);
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 59 ms 1372 KB Output is correct
2 Correct 57 ms 1372 KB Output is correct
3 Correct 51 ms 1368 KB Output is correct
4 Correct 77 ms 1532 KB Output is correct
5 Correct 71 ms 1372 KB Output is correct
6 Correct 82 ms 1368 KB Output is correct
7 Correct 115 ms 1528 KB Output is correct
8 Correct 78 ms 1368 KB Output is correct
9 Correct 67 ms 1372 KB Output is correct
10 Correct 73 ms 1484 KB Output is correct
11 Correct 171 ms 1372 KB Output is correct
12 Correct 27 ms 604 KB Output is correct
13 Correct 9 ms 712 KB Output is correct
14 Correct 27 ms 712 KB Output is correct
15 Correct 7 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 1524 KB Output is correct
2 Correct 197 ms 1372 KB Output is correct
3 Correct 178 ms 1576 KB Output is correct
4 Correct 176 ms 1372 KB Output is correct
5 Correct 293 ms 1528 KB Output is correct
6 Correct 365 ms 1620 KB Output is correct
7 Correct 342 ms 1536 KB Output is correct
8 Correct 360 ms 1528 KB Output is correct
9 Correct 322 ms 1532 KB Output is correct
10 Correct 633 ms 1532 KB Output is correct
11 Correct 670 ms 1532 KB Output is correct
12 Correct 778 ms 1368 KB Output is correct
13 Correct 724 ms 1536 KB Output is correct
14 Correct 918 ms 1536 KB Output is correct
15 Correct 849 ms 1536 KB Output is correct
16 Correct 827 ms 1620 KB Output is correct
17 Correct 881 ms 1616 KB Output is correct
18 Correct 615 ms 1536 KB Output is correct
19 Correct 548 ms 1372 KB Output is correct
20 Correct 668 ms 1532 KB Output is correct
21 Correct 620 ms 1532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 1532 KB Output is correct
2 Correct 221 ms 1428 KB Output is correct
3 Correct 240 ms 1536 KB Output is correct
4 Correct 157 ms 1364 KB Output is correct
5 Correct 158 ms 1688 KB Output is correct
6 Correct 358 ms 1528 KB Output is correct
7 Correct 428 ms 1616 KB Output is correct
8 Correct 360 ms 1372 KB Output is correct
9 Correct 408 ms 1528 KB Output is correct
10 Correct 874 ms 1528 KB Output is correct
11 Correct 919 ms 1536 KB Output is correct
12 Correct 902 ms 1532 KB Output is correct
13 Correct 949 ms 1620 KB Output is correct
14 Correct 912 ms 1536 KB Output is correct
15 Correct 841 ms 1368 KB Output is correct
16 Correct 872 ms 1536 KB Output is correct
17 Correct 858 ms 1620 KB Output is correct
18 Correct 237 ms 1532 KB Output is correct
19 Correct 197 ms 1528 KB Output is correct
20 Correct 221 ms 1536 KB Output is correct
21 Correct 178 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 307 ms 1372 KB Output is correct
2 Correct 210 ms 1372 KB Output is correct
3 Correct 325 ms 1364 KB Output is correct
4 Correct 184 ms 1320 KB Output is correct
5 Correct 195 ms 1428 KB Output is correct
6 Correct 196 ms 1532 KB Output is correct
7 Correct 182 ms 1528 KB Output is correct
8 Correct 213 ms 1528 KB Output is correct
9 Correct 214 ms 1532 KB Output is correct
10 Correct 445 ms 1536 KB Output is correct
11 Correct 543 ms 1364 KB Output is correct
12 Correct 379 ms 1524 KB Output is correct
13 Correct 366 ms 1372 KB Output is correct
14 Correct 414 ms 1524 KB Output is correct
15 Correct 327 ms 1532 KB Output is correct
16 Correct 375 ms 1624 KB Output is correct
17 Correct 454 ms 1372 KB Output is correct
18 Correct 171 ms 1616 KB Output is correct
19 Correct 176 ms 1372 KB Output is correct
20 Correct 164 ms 1532 KB Output is correct
21 Correct 139 ms 1624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 1372 KB Output is correct
2 Correct 57 ms 1372 KB Output is correct
3 Correct 51 ms 1368 KB Output is correct
4 Correct 77 ms 1532 KB Output is correct
5 Correct 71 ms 1372 KB Output is correct
6 Correct 82 ms 1368 KB Output is correct
7 Correct 115 ms 1528 KB Output is correct
8 Correct 78 ms 1368 KB Output is correct
9 Correct 67 ms 1372 KB Output is correct
10 Correct 73 ms 1484 KB Output is correct
11 Correct 171 ms 1372 KB Output is correct
12 Correct 27 ms 604 KB Output is correct
13 Correct 9 ms 712 KB Output is correct
14 Correct 27 ms 712 KB Output is correct
15 Correct 7 ms 604 KB Output is correct
16 Correct 179 ms 1524 KB Output is correct
17 Correct 197 ms 1372 KB Output is correct
18 Correct 178 ms 1576 KB Output is correct
19 Correct 176 ms 1372 KB Output is correct
20 Correct 293 ms 1528 KB Output is correct
21 Correct 365 ms 1620 KB Output is correct
22 Correct 342 ms 1536 KB Output is correct
23 Correct 360 ms 1528 KB Output is correct
24 Correct 322 ms 1532 KB Output is correct
25 Correct 633 ms 1532 KB Output is correct
26 Correct 670 ms 1532 KB Output is correct
27 Correct 778 ms 1368 KB Output is correct
28 Correct 724 ms 1536 KB Output is correct
29 Correct 918 ms 1536 KB Output is correct
30 Correct 849 ms 1536 KB Output is correct
31 Correct 827 ms 1620 KB Output is correct
32 Correct 881 ms 1616 KB Output is correct
33 Correct 615 ms 1536 KB Output is correct
34 Correct 548 ms 1372 KB Output is correct
35 Correct 668 ms 1532 KB Output is correct
36 Correct 620 ms 1532 KB Output is correct
37 Correct 177 ms 1532 KB Output is correct
38 Correct 221 ms 1428 KB Output is correct
39 Correct 240 ms 1536 KB Output is correct
40 Correct 157 ms 1364 KB Output is correct
41 Correct 158 ms 1688 KB Output is correct
42 Correct 358 ms 1528 KB Output is correct
43 Correct 428 ms 1616 KB Output is correct
44 Correct 360 ms 1372 KB Output is correct
45 Correct 408 ms 1528 KB Output is correct
46 Correct 874 ms 1528 KB Output is correct
47 Correct 919 ms 1536 KB Output is correct
48 Correct 902 ms 1532 KB Output is correct
49 Correct 949 ms 1620 KB Output is correct
50 Correct 912 ms 1536 KB Output is correct
51 Correct 841 ms 1368 KB Output is correct
52 Correct 872 ms 1536 KB Output is correct
53 Correct 858 ms 1620 KB Output is correct
54 Correct 237 ms 1532 KB Output is correct
55 Correct 197 ms 1528 KB Output is correct
56 Correct 221 ms 1536 KB Output is correct
57 Correct 178 ms 1616 KB Output is correct
58 Correct 307 ms 1372 KB Output is correct
59 Correct 210 ms 1372 KB Output is correct
60 Correct 325 ms 1364 KB Output is correct
61 Correct 184 ms 1320 KB Output is correct
62 Correct 195 ms 1428 KB Output is correct
63 Correct 196 ms 1532 KB Output is correct
64 Correct 182 ms 1528 KB Output is correct
65 Correct 213 ms 1528 KB Output is correct
66 Correct 214 ms 1532 KB Output is correct
67 Correct 445 ms 1536 KB Output is correct
68 Correct 543 ms 1364 KB Output is correct
69 Correct 379 ms 1524 KB Output is correct
70 Correct 366 ms 1372 KB Output is correct
71 Correct 414 ms 1524 KB Output is correct
72 Correct 327 ms 1532 KB Output is correct
73 Correct 375 ms 1624 KB Output is correct
74 Correct 454 ms 1372 KB Output is correct
75 Correct 171 ms 1616 KB Output is correct
76 Correct 176 ms 1372 KB Output is correct
77 Correct 164 ms 1532 KB Output is correct
78 Correct 139 ms 1624 KB Output is correct
79 Correct 199 ms 1532 KB Output is correct
80 Correct 410 ms 1364 KB Output is correct
81 Correct 204 ms 1372 KB Output is correct
82 Correct 244 ms 1532 KB Output is correct
83 Correct 187 ms 1536 KB Output is correct
84 Correct 638 ms 1528 KB Output is correct
85 Execution timed out 1042 ms 1368 KB Time limit exceeded
86 Halted 0 ms 0 KB -