#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN=10;
int q, n, a[mxN];
string s;
ll dp[mxN+1][301][11][11], dp2[mxN+1][301];
struct frame {
vector<int> v;
int b1, b2;
string s;
};
vector<frame> vs, vf;
void solve() {
cin >> n >> s;
for(int i=0; i<n; ++i)
cin >> a[i];
memset(dp, 0, sizeof(dp));
memset(dp2, 0, sizeof(dp2));
dp2[0][0]=1;
for(int i=0; i<n; ++i) {
for(int j=0; j<=300; ++j) {
for(int k=0; k<=10; ++k)
for(int l=0; l<=10; ++l)
dp[i][j][k][l]+=dp2[i][j];
for(frame f : (i<n-1?vs:vf)) {
bool ok=1;
for(int k=0; k<f.s.size()&&ok; ++k)
ok=s[2*i+k]=='?'||s[2*i+k]==f.s[k];
if(!ok)
continue;
int bs=j;
for(int b : f.v)
bs+=b;
for(int k=0; k<=10; ++k) {
if(k^f.v[0])
continue;
for(int l=0; l<=10; ++l) {
if((f.v.size()>1&&l^f.v[1])||!dp[i][j][k][l])
continue;
if(f.b1||f.b2||f.v.size()<2||~a[i]) {
for(int k2=0; k2<=10; ++k2) {
if(f.v.size()<2&&k2^l)
continue;
for(int l2=0; l2<=10; ++l2) {
int j2=bs+f.b1*k2+f.b2*l2;
if(a[i]<0||a[i]==j2)
dp[i+1][j2][k2][l2]+=dp[i][j][k][l];
}
}
} else
dp2[i+1][bs]+=dp[i][j][k][l];
}
}
}
}
}
ll ans=0;
for(int i=0; i<=300; ++i)
ans+=dp[n][i][0][0]+dp2[n][i];
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
vs.push_back({{10}, 1, 1, "x-"});
for(int i=0; i<10; ++i)
vs.push_back({{i, 10-i}, 1, 0, to_string(i)+"/"});
for(int i=0; i<10; ++i)
for(int j=0; j<10-i; ++j)
vs.push_back({{i, j}, 0, 0, to_string(i)+to_string(j)});
vf.push_back({{10, 10, 10}, 0, 0, "xxx"});
for(int i=0; i<10; ++i)
vf.push_back({{10, 10, i}, 0, 0, "xx"+to_string(i)});
for(int i=0; i<10; ++i)
vf.push_back({{10, i, 10-i}, 0, 0, "x"+to_string(i)+"/"});
for(int i=0; i<10; ++i)
for(int j=0; j<10-i; ++j)
vf.push_back({{10, i, j}, 0, 0, "x"+to_string(i)+to_string(j)});
for(int i=0; i<10; ++i)
vf.push_back({{i, 10-i, 10}, 0, 0, to_string(i)+"/x"});
for(int i=0; i<10; ++i)
for(int j=0; j<10; ++j)
vf.push_back({{i, 10-i, j}, 0, 0, to_string(i)+"/"+to_string(j)});
for(int i=0; i<10; ++i)
for(int j=0; j<10-i; ++j)
vf.push_back({{i, j}, 0, 0, to_string(i)+to_string(j)+"-"});
cin >> q;
while(q--)
solve();
}
Compilation message
bow.cpp: In function 'void solve()':
bow.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0; k<f.s.size()&&ok; ++k)
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
221 ms |
3704 KB |
Output is correct |
2 |
Correct |
231 ms |
3704 KB |
Output is correct |
3 |
Correct |
227 ms |
3704 KB |
Output is correct |
4 |
Correct |
252 ms |
3704 KB |
Output is correct |
5 |
Correct |
259 ms |
3584 KB |
Output is correct |
6 |
Correct |
267 ms |
3588 KB |
Output is correct |
7 |
Correct |
280 ms |
3704 KB |
Output is correct |
8 |
Correct |
265 ms |
3584 KB |
Output is correct |
9 |
Correct |
259 ms |
3576 KB |
Output is correct |
10 |
Correct |
266 ms |
3704 KB |
Output is correct |
11 |
Correct |
364 ms |
3580 KB |
Output is correct |
12 |
Correct |
254 ms |
3704 KB |
Output is correct |
13 |
Correct |
55 ms |
3576 KB |
Output is correct |
14 |
Correct |
253 ms |
3616 KB |
Output is correct |
15 |
Correct |
64 ms |
3576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
3704 KB |
Output is correct |
2 |
Correct |
337 ms |
3576 KB |
Output is correct |
3 |
Correct |
326 ms |
3580 KB |
Output is correct |
4 |
Correct |
329 ms |
3580 KB |
Output is correct |
5 |
Correct |
364 ms |
3704 KB |
Output is correct |
6 |
Correct |
418 ms |
3704 KB |
Output is correct |
7 |
Correct |
427 ms |
3704 KB |
Output is correct |
8 |
Correct |
417 ms |
3576 KB |
Output is correct |
9 |
Correct |
449 ms |
3704 KB |
Output is correct |
10 |
Correct |
562 ms |
3576 KB |
Output is correct |
11 |
Correct |
580 ms |
3704 KB |
Output is correct |
12 |
Correct |
573 ms |
3704 KB |
Output is correct |
13 |
Correct |
605 ms |
3576 KB |
Output is correct |
14 |
Correct |
632 ms |
3704 KB |
Output is correct |
15 |
Correct |
621 ms |
3704 KB |
Output is correct |
16 |
Correct |
627 ms |
3704 KB |
Output is correct |
17 |
Correct |
622 ms |
3576 KB |
Output is correct |
18 |
Correct |
528 ms |
3676 KB |
Output is correct |
19 |
Correct |
513 ms |
3576 KB |
Output is correct |
20 |
Correct |
575 ms |
3576 KB |
Output is correct |
21 |
Correct |
549 ms |
3576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
3624 KB |
Output is correct |
2 |
Correct |
339 ms |
3576 KB |
Output is correct |
3 |
Correct |
337 ms |
3704 KB |
Output is correct |
4 |
Correct |
300 ms |
3704 KB |
Output is correct |
5 |
Correct |
273 ms |
3576 KB |
Output is correct |
6 |
Correct |
435 ms |
3588 KB |
Output is correct |
7 |
Correct |
452 ms |
3576 KB |
Output is correct |
8 |
Correct |
441 ms |
3704 KB |
Output is correct |
9 |
Correct |
457 ms |
3576 KB |
Output is correct |
10 |
Correct |
632 ms |
3580 KB |
Output is correct |
11 |
Correct |
618 ms |
3704 KB |
Output is correct |
12 |
Correct |
621 ms |
3576 KB |
Output is correct |
13 |
Correct |
624 ms |
3580 KB |
Output is correct |
14 |
Correct |
589 ms |
3704 KB |
Output is correct |
15 |
Correct |
587 ms |
3576 KB |
Output is correct |
16 |
Correct |
579 ms |
3580 KB |
Output is correct |
17 |
Correct |
595 ms |
3704 KB |
Output is correct |
18 |
Correct |
393 ms |
3576 KB |
Output is correct |
19 |
Correct |
379 ms |
3704 KB |
Output is correct |
20 |
Correct |
383 ms |
3704 KB |
Output is correct |
21 |
Correct |
366 ms |
3580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
263 ms |
3592 KB |
Output is correct |
2 |
Correct |
300 ms |
3616 KB |
Output is correct |
3 |
Correct |
318 ms |
3704 KB |
Output is correct |
4 |
Correct |
278 ms |
3576 KB |
Output is correct |
5 |
Correct |
275 ms |
3704 KB |
Output is correct |
6 |
Correct |
312 ms |
3704 KB |
Output is correct |
7 |
Correct |
287 ms |
3576 KB |
Output is correct |
8 |
Correct |
304 ms |
3704 KB |
Output is correct |
9 |
Correct |
293 ms |
3576 KB |
Output is correct |
10 |
Correct |
403 ms |
3576 KB |
Output is correct |
11 |
Correct |
389 ms |
3616 KB |
Output is correct |
12 |
Correct |
368 ms |
3576 KB |
Output is correct |
13 |
Correct |
350 ms |
3624 KB |
Output is correct |
14 |
Correct |
400 ms |
3704 KB |
Output is correct |
15 |
Correct |
392 ms |
3704 KB |
Output is correct |
16 |
Correct |
413 ms |
3576 KB |
Output is correct |
17 |
Correct |
414 ms |
3704 KB |
Output is correct |
18 |
Correct |
349 ms |
3708 KB |
Output is correct |
19 |
Correct |
357 ms |
3576 KB |
Output is correct |
20 |
Correct |
356 ms |
3576 KB |
Output is correct |
21 |
Correct |
341 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
221 ms |
3704 KB |
Output is correct |
2 |
Correct |
231 ms |
3704 KB |
Output is correct |
3 |
Correct |
227 ms |
3704 KB |
Output is correct |
4 |
Correct |
252 ms |
3704 KB |
Output is correct |
5 |
Correct |
259 ms |
3584 KB |
Output is correct |
6 |
Correct |
267 ms |
3588 KB |
Output is correct |
7 |
Correct |
280 ms |
3704 KB |
Output is correct |
8 |
Correct |
265 ms |
3584 KB |
Output is correct |
9 |
Correct |
259 ms |
3576 KB |
Output is correct |
10 |
Correct |
266 ms |
3704 KB |
Output is correct |
11 |
Correct |
364 ms |
3580 KB |
Output is correct |
12 |
Correct |
254 ms |
3704 KB |
Output is correct |
13 |
Correct |
55 ms |
3576 KB |
Output is correct |
14 |
Correct |
253 ms |
3616 KB |
Output is correct |
15 |
Correct |
64 ms |
3576 KB |
Output is correct |
16 |
Correct |
217 ms |
3704 KB |
Output is correct |
17 |
Correct |
337 ms |
3576 KB |
Output is correct |
18 |
Correct |
326 ms |
3580 KB |
Output is correct |
19 |
Correct |
329 ms |
3580 KB |
Output is correct |
20 |
Correct |
364 ms |
3704 KB |
Output is correct |
21 |
Correct |
418 ms |
3704 KB |
Output is correct |
22 |
Correct |
427 ms |
3704 KB |
Output is correct |
23 |
Correct |
417 ms |
3576 KB |
Output is correct |
24 |
Correct |
449 ms |
3704 KB |
Output is correct |
25 |
Correct |
562 ms |
3576 KB |
Output is correct |
26 |
Correct |
580 ms |
3704 KB |
Output is correct |
27 |
Correct |
573 ms |
3704 KB |
Output is correct |
28 |
Correct |
605 ms |
3576 KB |
Output is correct |
29 |
Correct |
632 ms |
3704 KB |
Output is correct |
30 |
Correct |
621 ms |
3704 KB |
Output is correct |
31 |
Correct |
627 ms |
3704 KB |
Output is correct |
32 |
Correct |
622 ms |
3576 KB |
Output is correct |
33 |
Correct |
528 ms |
3676 KB |
Output is correct |
34 |
Correct |
513 ms |
3576 KB |
Output is correct |
35 |
Correct |
575 ms |
3576 KB |
Output is correct |
36 |
Correct |
549 ms |
3576 KB |
Output is correct |
37 |
Correct |
165 ms |
3624 KB |
Output is correct |
38 |
Correct |
339 ms |
3576 KB |
Output is correct |
39 |
Correct |
337 ms |
3704 KB |
Output is correct |
40 |
Correct |
300 ms |
3704 KB |
Output is correct |
41 |
Correct |
273 ms |
3576 KB |
Output is correct |
42 |
Correct |
435 ms |
3588 KB |
Output is correct |
43 |
Correct |
452 ms |
3576 KB |
Output is correct |
44 |
Correct |
441 ms |
3704 KB |
Output is correct |
45 |
Correct |
457 ms |
3576 KB |
Output is correct |
46 |
Correct |
632 ms |
3580 KB |
Output is correct |
47 |
Correct |
618 ms |
3704 KB |
Output is correct |
48 |
Correct |
621 ms |
3576 KB |
Output is correct |
49 |
Correct |
624 ms |
3580 KB |
Output is correct |
50 |
Correct |
589 ms |
3704 KB |
Output is correct |
51 |
Correct |
587 ms |
3576 KB |
Output is correct |
52 |
Correct |
579 ms |
3580 KB |
Output is correct |
53 |
Correct |
595 ms |
3704 KB |
Output is correct |
54 |
Correct |
393 ms |
3576 KB |
Output is correct |
55 |
Correct |
379 ms |
3704 KB |
Output is correct |
56 |
Correct |
383 ms |
3704 KB |
Output is correct |
57 |
Correct |
366 ms |
3580 KB |
Output is correct |
58 |
Correct |
263 ms |
3592 KB |
Output is correct |
59 |
Correct |
300 ms |
3616 KB |
Output is correct |
60 |
Correct |
318 ms |
3704 KB |
Output is correct |
61 |
Correct |
278 ms |
3576 KB |
Output is correct |
62 |
Correct |
275 ms |
3704 KB |
Output is correct |
63 |
Correct |
312 ms |
3704 KB |
Output is correct |
64 |
Correct |
287 ms |
3576 KB |
Output is correct |
65 |
Correct |
304 ms |
3704 KB |
Output is correct |
66 |
Correct |
293 ms |
3576 KB |
Output is correct |
67 |
Correct |
403 ms |
3576 KB |
Output is correct |
68 |
Correct |
389 ms |
3616 KB |
Output is correct |
69 |
Correct |
368 ms |
3576 KB |
Output is correct |
70 |
Correct |
350 ms |
3624 KB |
Output is correct |
71 |
Correct |
400 ms |
3704 KB |
Output is correct |
72 |
Correct |
392 ms |
3704 KB |
Output is correct |
73 |
Correct |
413 ms |
3576 KB |
Output is correct |
74 |
Correct |
414 ms |
3704 KB |
Output is correct |
75 |
Correct |
349 ms |
3708 KB |
Output is correct |
76 |
Correct |
357 ms |
3576 KB |
Output is correct |
77 |
Correct |
356 ms |
3576 KB |
Output is correct |
78 |
Correct |
341 ms |
3704 KB |
Output is correct |
79 |
Correct |
174 ms |
3676 KB |
Output is correct |
80 |
Correct |
396 ms |
3592 KB |
Output is correct |
81 |
Correct |
364 ms |
3676 KB |
Output is correct |
82 |
Correct |
354 ms |
3576 KB |
Output is correct |
83 |
Correct |
345 ms |
3624 KB |
Output is correct |
84 |
Correct |
528 ms |
3584 KB |
Output is correct |
85 |
Correct |
578 ms |
3592 KB |
Output is correct |
86 |
Correct |
516 ms |
3704 KB |
Output is correct |
87 |
Correct |
550 ms |
3580 KB |
Output is correct |
88 |
Correct |
568 ms |
3704 KB |
Output is correct |
89 |
Correct |
581 ms |
3704 KB |
Output is correct |
90 |
Correct |
575 ms |
3676 KB |
Output is correct |
91 |
Correct |
580 ms |
3704 KB |
Output is correct |
92 |
Correct |
331 ms |
3704 KB |
Output is correct |
93 |
Correct |
923 ms |
3588 KB |
Output is correct |
94 |
Correct |
924 ms |
3704 KB |
Output is correct |
95 |
Correct |
923 ms |
3704 KB |
Output is correct |
96 |
Correct |
936 ms |
3704 KB |
Output is correct |
97 |
Correct |
939 ms |
3576 KB |
Output is correct |
98 |
Correct |
930 ms |
3588 KB |
Output is correct |
99 |
Execution timed out |
1018 ms |
3576 KB |
Time limit exceeded |
100 |
Halted |
0 ms |
0 KB |
- |