답안 #956781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956781 2024-04-02T13:01:52 Z GrindMachine Bowling (BOI15_bow) C++17
100 / 100
918 ms 1696 KB
#pragma GCC optimize("O3,unroll-loops")

#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 1368 KB Output is correct
2 Correct 70 ms 1368 KB Output is correct
3 Correct 45 ms 1364 KB Output is correct
4 Correct 55 ms 1528 KB Output is correct
5 Correct 64 ms 1368 KB Output is correct
6 Correct 70 ms 1368 KB Output is correct
7 Correct 84 ms 1532 KB Output is correct
8 Correct 68 ms 1528 KB Output is correct
9 Correct 61 ms 1524 KB Output is correct
10 Correct 67 ms 1368 KB Output is correct
11 Correct 156 ms 1368 KB Output is correct
12 Correct 39 ms 600 KB Output is correct
13 Correct 6 ms 604 KB Output is correct
14 Correct 24 ms 684 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 1372 KB Output is correct
2 Correct 192 ms 1368 KB Output is correct
3 Correct 155 ms 1360 KB Output is correct
4 Correct 163 ms 1360 KB Output is correct
5 Correct 219 ms 1368 KB Output is correct
6 Correct 312 ms 1528 KB Output is correct
7 Correct 302 ms 1372 KB Output is correct
8 Correct 294 ms 1528 KB Output is correct
9 Correct 278 ms 1524 KB Output is correct
10 Correct 562 ms 1524 KB Output is correct
11 Correct 611 ms 1372 KB Output is correct
12 Correct 647 ms 1532 KB Output is correct
13 Correct 658 ms 1528 KB Output is correct
14 Correct 801 ms 1624 KB Output is correct
15 Correct 788 ms 1616 KB Output is correct
16 Correct 854 ms 1532 KB Output is correct
17 Correct 776 ms 1528 KB Output is correct
18 Correct 714 ms 1532 KB Output is correct
19 Correct 532 ms 1528 KB Output is correct
20 Correct 702 ms 1544 KB Output is correct
21 Correct 566 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 1524 KB Output is correct
2 Correct 201 ms 1624 KB Output is correct
3 Correct 154 ms 1624 KB Output is correct
4 Correct 129 ms 1528 KB Output is correct
5 Correct 112 ms 1420 KB Output is correct
6 Correct 337 ms 1524 KB Output is correct
7 Correct 386 ms 1528 KB Output is correct
8 Correct 318 ms 1532 KB Output is correct
9 Correct 386 ms 1532 KB Output is correct
10 Correct 849 ms 1528 KB Output is correct
11 Correct 844 ms 1528 KB Output is correct
12 Correct 815 ms 1524 KB Output is correct
13 Correct 843 ms 1524 KB Output is correct
14 Correct 751 ms 1528 KB Output is correct
15 Correct 782 ms 1524 KB Output is correct
16 Correct 808 ms 1524 KB Output is correct
17 Correct 772 ms 1528 KB Output is correct
18 Correct 173 ms 1372 KB Output is correct
19 Correct 189 ms 1532 KB Output is correct
20 Correct 198 ms 1372 KB Output is correct
21 Correct 167 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 310 ms 1528 KB Output is correct
2 Correct 181 ms 1372 KB Output is correct
3 Correct 241 ms 1364 KB Output is correct
4 Correct 168 ms 1616 KB Output is correct
5 Correct 173 ms 1360 KB Output is correct
6 Correct 169 ms 1524 KB Output is correct
7 Correct 170 ms 1520 KB Output is correct
8 Correct 181 ms 1372 KB Output is correct
9 Correct 211 ms 1368 KB Output is correct
10 Correct 408 ms 1368 KB Output is correct
11 Correct 367 ms 1372 KB Output is correct
12 Correct 366 ms 1524 KB Output is correct
13 Correct 296 ms 1520 KB Output is correct
14 Correct 306 ms 1524 KB Output is correct
15 Correct 311 ms 1368 KB Output is correct
16 Correct 329 ms 1692 KB Output is correct
17 Correct 363 ms 1520 KB Output is correct
18 Correct 160 ms 1372 KB Output is correct
19 Correct 167 ms 1372 KB Output is correct
20 Correct 148 ms 1524 KB Output is correct
21 Correct 137 ms 1524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 1368 KB Output is correct
2 Correct 70 ms 1368 KB Output is correct
3 Correct 45 ms 1364 KB Output is correct
4 Correct 55 ms 1528 KB Output is correct
5 Correct 64 ms 1368 KB Output is correct
6 Correct 70 ms 1368 KB Output is correct
7 Correct 84 ms 1532 KB Output is correct
8 Correct 68 ms 1528 KB Output is correct
9 Correct 61 ms 1524 KB Output is correct
10 Correct 67 ms 1368 KB Output is correct
11 Correct 156 ms 1368 KB Output is correct
12 Correct 39 ms 600 KB Output is correct
13 Correct 6 ms 604 KB Output is correct
14 Correct 24 ms 684 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
16 Correct 165 ms 1372 KB Output is correct
17 Correct 192 ms 1368 KB Output is correct
18 Correct 155 ms 1360 KB Output is correct
19 Correct 163 ms 1360 KB Output is correct
20 Correct 219 ms 1368 KB Output is correct
21 Correct 312 ms 1528 KB Output is correct
22 Correct 302 ms 1372 KB Output is correct
23 Correct 294 ms 1528 KB Output is correct
24 Correct 278 ms 1524 KB Output is correct
25 Correct 562 ms 1524 KB Output is correct
26 Correct 611 ms 1372 KB Output is correct
27 Correct 647 ms 1532 KB Output is correct
28 Correct 658 ms 1528 KB Output is correct
29 Correct 801 ms 1624 KB Output is correct
30 Correct 788 ms 1616 KB Output is correct
31 Correct 854 ms 1532 KB Output is correct
32 Correct 776 ms 1528 KB Output is correct
33 Correct 714 ms 1532 KB Output is correct
34 Correct 532 ms 1528 KB Output is correct
35 Correct 702 ms 1544 KB Output is correct
36 Correct 566 ms 1528 KB Output is correct
37 Correct 117 ms 1524 KB Output is correct
38 Correct 201 ms 1624 KB Output is correct
39 Correct 154 ms 1624 KB Output is correct
40 Correct 129 ms 1528 KB Output is correct
41 Correct 112 ms 1420 KB Output is correct
42 Correct 337 ms 1524 KB Output is correct
43 Correct 386 ms 1528 KB Output is correct
44 Correct 318 ms 1532 KB Output is correct
45 Correct 386 ms 1532 KB Output is correct
46 Correct 849 ms 1528 KB Output is correct
47 Correct 844 ms 1528 KB Output is correct
48 Correct 815 ms 1524 KB Output is correct
49 Correct 843 ms 1524 KB Output is correct
50 Correct 751 ms 1528 KB Output is correct
51 Correct 782 ms 1524 KB Output is correct
52 Correct 808 ms 1524 KB Output is correct
53 Correct 772 ms 1528 KB Output is correct
54 Correct 173 ms 1372 KB Output is correct
55 Correct 189 ms 1532 KB Output is correct
56 Correct 198 ms 1372 KB Output is correct
57 Correct 167 ms 1528 KB Output is correct
58 Correct 310 ms 1528 KB Output is correct
59 Correct 181 ms 1372 KB Output is correct
60 Correct 241 ms 1364 KB Output is correct
61 Correct 168 ms 1616 KB Output is correct
62 Correct 173 ms 1360 KB Output is correct
63 Correct 169 ms 1524 KB Output is correct
64 Correct 170 ms 1520 KB Output is correct
65 Correct 181 ms 1372 KB Output is correct
66 Correct 211 ms 1368 KB Output is correct
67 Correct 408 ms 1368 KB Output is correct
68 Correct 367 ms 1372 KB Output is correct
69 Correct 366 ms 1524 KB Output is correct
70 Correct 296 ms 1520 KB Output is correct
71 Correct 306 ms 1524 KB Output is correct
72 Correct 311 ms 1368 KB Output is correct
73 Correct 329 ms 1692 KB Output is correct
74 Correct 363 ms 1520 KB Output is correct
75 Correct 160 ms 1372 KB Output is correct
76 Correct 167 ms 1372 KB Output is correct
77 Correct 148 ms 1524 KB Output is correct
78 Correct 137 ms 1524 KB Output is correct
79 Correct 195 ms 1372 KB Output is correct
80 Correct 269 ms 1528 KB Output is correct
81 Correct 178 ms 1528 KB Output is correct
82 Correct 200 ms 1532 KB Output is correct
83 Correct 170 ms 1532 KB Output is correct
84 Correct 568 ms 1532 KB Output is correct
85 Correct 632 ms 1528 KB Output is correct
86 Correct 583 ms 1696 KB Output is correct
87 Correct 599 ms 1688 KB Output is correct
88 Correct 614 ms 1536 KB Output is correct
89 Correct 667 ms 1368 KB Output is correct
90 Correct 625 ms 1372 KB Output is correct
91 Correct 632 ms 1532 KB Output is correct
92 Correct 105 ms 1532 KB Output is correct
93 Correct 849 ms 1528 KB Output is correct
94 Correct 839 ms 1372 KB Output is correct
95 Correct 918 ms 1536 KB Output is correct
96 Correct 857 ms 1372 KB Output is correct
97 Correct 852 ms 1536 KB Output is correct
98 Correct 819 ms 1532 KB Output is correct
99 Correct 821 ms 1552 KB Output is correct
100 Correct 845 ms 1616 KB Output is correct