Submission #60219

# Submission time Handle Problem Language Result Execution time Memory
60219 2018-07-23T21:09:08 Z Benq Bowling (BOI15_bow) C++11
33 / 100
924 ms 9580 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;


struct hsh {
    size_t operator()(const pi& k) const {
        return (ll)MOD*k.f+k.s; // bad, but you get the point
    }
};

int q, n, num[10];
ll m[2][3][301][301], M[2][3][301][301];
string tmp[10];

string gen(vi nex) {
    int lst = -1;
    string res;
    for (int i: nex) {
        if (i == -1) res += '-';
        else if (lst != -1 && i+lst == 10) {
            res += '/';
            lst = -1;
        } else if (i == 10) res += 'x';
        else {
            if (lst == -1) lst = 0;
            res += char('0'+i);
            lst += i;
        }
    }
    return res;
}

bool match(string bad, vi nex) {
    string t = gen(nex);
    F0R(i,sz(bad)) if (bad[i] != '?' && bad[i] != t[i]) return 0;
    return 1;
}


void tri(int a, int b, int c, int d, int x, vi y) {
    int val = m[a][b][c][d];
    int cur = d;
    for (int i: y) if (i != -1) {
        cur += i;
        if (a) c += i, d += i, cur += i, a --;
        if (b) d += i, cur += i, b --;
    }
    
    int posi = 0;
    if (x != n-1) {
        if (y[0] == 10) posi = 2;
        else if (y[0]+y[1] == 10) posi = 1;
    }
    
    if (x >= 2 && a == 0 && num[x-2] != -1 && c != num[x-2]) return;
    if (x >= 1 && b == 0 && num[x-1] != -1 && d != num[x-1]) return;
    if (posi == 0 && num[x] != -1 && cur != num[x]) return;
    M[b][posi][d][cur] += val;
}

void process(int x) {
    vector<vi> posi;
    
    if (x != n-1) {
        if (match(tmp[x],{10,-1})) posi.pb({10,-1});
        F0R(i,10) F0R(j,11-i) if (match(tmp[x],{i,j})) posi.pb({i,j});
    } else {
        F0R(i,11) if (match(tmp[x],{10,10,i})) posi.pb({10,10,i});
        F0R(i,10) F0R(j,11-i) if (match(tmp[x],{10,i,j})) posi.pb({10,i,j});
        F0R(i,10) F0R(j,11) if (match(tmp[x],{i,10-i,j})) posi.pb({i,10-i,j});
        F0R(i,10) F0R(j,10-i) if (match(tmp[x],{i,j,-1})) posi.pb({i,j,-1});
    }
    
    vector<vi> POSI;
    F0R(a,2) F0R(b,3) F0R(c,301) F0R(d,301) 
        if (m[a][b][c][d]) POSI.pb({a,b,c,d});
    
    for (auto v: posi) for (auto V: POSI)
        tri(V[0],V[1],V[2],V[3],x,v);
        
    F0R(a,2) F0R(b,3) F0R(c,301) F0R(d,301) {
        m[a][b][c][d] = M[a][b][c][d];
        M[a][b][c][d] = 0;
    }
}

void solve() {
    cin >> n;
    string s; cin >> s;
    F0R(i,n-1) tmp[i] = s.substr(2*i,2);
    tmp[n-1] = s.substr(2*(n-1),3);
    F0R(i,n) cin >> num[i];
    
    memset(m,0,sizeof m);
    m[0][0][0][0] = 1;
    F0R(i,n) process(i);
    ll ans = 0;
    F0R(i,301) F0R(j,301) ans += m[0][0][i][j];
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> q;
    F0R(i,q) solve();
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# Verdict Execution time Memory Grader output
1 Correct 240 ms 8824 KB Output is correct
2 Correct 257 ms 9064 KB Output is correct
3 Correct 326 ms 9116 KB Output is correct
4 Correct 261 ms 9116 KB Output is correct
5 Correct 250 ms 9116 KB Output is correct
6 Correct 290 ms 9300 KB Output is correct
7 Correct 373 ms 9300 KB Output is correct
8 Correct 403 ms 9300 KB Output is correct
9 Correct 255 ms 9300 KB Output is correct
10 Correct 306 ms 9300 KB Output is correct
11 Correct 454 ms 9300 KB Output is correct
12 Correct 131 ms 9300 KB Output is correct
13 Correct 32 ms 9300 KB Output is correct
14 Correct 121 ms 9300 KB Output is correct
15 Correct 39 ms 9300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 325 ms 9312 KB Output is correct
2 Correct 370 ms 9312 KB Output is correct
3 Correct 327 ms 9312 KB Output is correct
4 Correct 344 ms 9312 KB Output is correct
5 Correct 408 ms 9312 KB Output is correct
6 Correct 590 ms 9312 KB Output is correct
7 Correct 545 ms 9312 KB Output is correct
8 Correct 533 ms 9312 KB Output is correct
9 Correct 508 ms 9312 KB Output is correct
10 Correct 722 ms 9324 KB Output is correct
11 Correct 793 ms 9324 KB Output is correct
12 Correct 632 ms 9360 KB Output is correct
13 Correct 922 ms 9360 KB Output is correct
14 Correct 677 ms 9360 KB Output is correct
15 Correct 572 ms 9360 KB Output is correct
16 Correct 590 ms 9360 KB Output is correct
17 Correct 651 ms 9360 KB Output is correct
18 Correct 924 ms 9580 KB Output is correct
19 Correct 882 ms 9580 KB Output is correct
20 Correct 775 ms 9580 KB Output is correct
21 Correct 911 ms 9580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 308 ms 9580 KB Output is correct
2 Correct 316 ms 9580 KB Output is correct
3 Correct 351 ms 9580 KB Output is correct
4 Correct 367 ms 9580 KB Output is correct
5 Correct 349 ms 9580 KB Output is correct
6 Correct 426 ms 9580 KB Output is correct
7 Correct 446 ms 9580 KB Output is correct
8 Correct 558 ms 9580 KB Output is correct
9 Correct 543 ms 9580 KB Output is correct
10 Correct 501 ms 9580 KB Output is correct
11 Correct 434 ms 9580 KB Output is correct
12 Correct 509 ms 9580 KB Output is correct
13 Correct 450 ms 9580 KB Output is correct
14 Incorrect 500 ms 9580 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 351 ms 9580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 240 ms 8824 KB Output is correct
2 Correct 257 ms 9064 KB Output is correct
3 Correct 326 ms 9116 KB Output is correct
4 Correct 261 ms 9116 KB Output is correct
5 Correct 250 ms 9116 KB Output is correct
6 Correct 290 ms 9300 KB Output is correct
7 Correct 373 ms 9300 KB Output is correct
8 Correct 403 ms 9300 KB Output is correct
9 Correct 255 ms 9300 KB Output is correct
10 Correct 306 ms 9300 KB Output is correct
11 Correct 454 ms 9300 KB Output is correct
12 Correct 131 ms 9300 KB Output is correct
13 Correct 32 ms 9300 KB Output is correct
14 Correct 121 ms 9300 KB Output is correct
15 Correct 39 ms 9300 KB Output is correct
16 Correct 325 ms 9312 KB Output is correct
17 Correct 370 ms 9312 KB Output is correct
18 Correct 327 ms 9312 KB Output is correct
19 Correct 344 ms 9312 KB Output is correct
20 Correct 408 ms 9312 KB Output is correct
21 Correct 590 ms 9312 KB Output is correct
22 Correct 545 ms 9312 KB Output is correct
23 Correct 533 ms 9312 KB Output is correct
24 Correct 508 ms 9312 KB Output is correct
25 Correct 722 ms 9324 KB Output is correct
26 Correct 793 ms 9324 KB Output is correct
27 Correct 632 ms 9360 KB Output is correct
28 Correct 922 ms 9360 KB Output is correct
29 Correct 677 ms 9360 KB Output is correct
30 Correct 572 ms 9360 KB Output is correct
31 Correct 590 ms 9360 KB Output is correct
32 Correct 651 ms 9360 KB Output is correct
33 Correct 924 ms 9580 KB Output is correct
34 Correct 882 ms 9580 KB Output is correct
35 Correct 775 ms 9580 KB Output is correct
36 Correct 911 ms 9580 KB Output is correct
37 Correct 308 ms 9580 KB Output is correct
38 Correct 316 ms 9580 KB Output is correct
39 Correct 351 ms 9580 KB Output is correct
40 Correct 367 ms 9580 KB Output is correct
41 Correct 349 ms 9580 KB Output is correct
42 Correct 426 ms 9580 KB Output is correct
43 Correct 446 ms 9580 KB Output is correct
44 Correct 558 ms 9580 KB Output is correct
45 Correct 543 ms 9580 KB Output is correct
46 Correct 501 ms 9580 KB Output is correct
47 Correct 434 ms 9580 KB Output is correct
48 Correct 509 ms 9580 KB Output is correct
49 Correct 450 ms 9580 KB Output is correct
50 Incorrect 500 ms 9580 KB Output isn't correct
51 Halted 0 ms 0 KB -