#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,bool strike,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,true,-1) and ok(h2,2 * n,true,-1) and ok(h3,2 * n + 1,true,-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,true,-1) and ok(h2,2 * n,false,-1) and ok(h3,2 * n + 1,false,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,false,-1) and ok(h2, 2 * n,false,h1))
{
for (int h3 = 0; h3 <= 10; h3++)
{
if (ok(h3,2 * n + 1,true,-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,false,-1) and ok(h2,2 * n,false,h1) and ok(-1,2 * n + 1,false,-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,true,-1) and ok(-1,2 * i - 2,false,-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,false,-1) and ok(h2p,2 * i - 2,false,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 |
275 ms |
100688 KB |
Output is correct |
2 |
Correct |
263 ms |
100596 KB |
Output is correct |
3 |
Correct |
272 ms |
100700 KB |
Output is correct |
4 |
Correct |
277 ms |
100700 KB |
Output is correct |
5 |
Correct |
281 ms |
100700 KB |
Output is correct |
6 |
Correct |
283 ms |
100968 KB |
Output is correct |
7 |
Correct |
357 ms |
100552 KB |
Output is correct |
8 |
Correct |
360 ms |
100696 KB |
Output is correct |
9 |
Correct |
319 ms |
100696 KB |
Output is correct |
10 |
Correct |
343 ms |
100696 KB |
Output is correct |
11 |
Correct |
344 ms |
100700 KB |
Output is correct |
12 |
Correct |
231 ms |
100536 KB |
Output is correct |
13 |
Correct |
52 ms |
100700 KB |
Output is correct |
14 |
Correct |
238 ms |
100696 KB |
Output is correct |
15 |
Correct |
59 ms |
100700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
100696 KB |
Output is correct |
2 |
Correct |
347 ms |
100696 KB |
Output is correct |
3 |
Correct |
307 ms |
100952 KB |
Output is correct |
4 |
Correct |
297 ms |
100696 KB |
Output is correct |
5 |
Correct |
349 ms |
100792 KB |
Output is correct |
6 |
Correct |
382 ms |
100696 KB |
Output is correct |
7 |
Correct |
438 ms |
100700 KB |
Output is correct |
8 |
Correct |
398 ms |
100700 KB |
Output is correct |
9 |
Correct |
377 ms |
100696 KB |
Output is correct |
10 |
Correct |
593 ms |
100700 KB |
Output is correct |
11 |
Correct |
562 ms |
100720 KB |
Output is correct |
12 |
Correct |
685 ms |
100948 KB |
Output is correct |
13 |
Correct |
621 ms |
100696 KB |
Output is correct |
14 |
Correct |
466 ms |
100696 KB |
Output is correct |
15 |
Correct |
449 ms |
100700 KB |
Output is correct |
16 |
Correct |
393 ms |
100700 KB |
Output is correct |
17 |
Correct |
448 ms |
100700 KB |
Output is correct |
18 |
Correct |
823 ms |
101200 KB |
Output is correct |
19 |
Correct |
795 ms |
100764 KB |
Output is correct |
20 |
Correct |
869 ms |
100700 KB |
Output is correct |
21 |
Correct |
908 ms |
100700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
100700 KB |
Output is correct |
2 |
Correct |
284 ms |
100700 KB |
Output is correct |
3 |
Correct |
293 ms |
100700 KB |
Output is correct |
4 |
Correct |
287 ms |
100788 KB |
Output is correct |
5 |
Correct |
270 ms |
100700 KB |
Output is correct |
6 |
Correct |
337 ms |
100700 KB |
Output is correct |
7 |
Correct |
334 ms |
100700 KB |
Output is correct |
8 |
Correct |
336 ms |
100700 KB |
Output is correct |
9 |
Correct |
344 ms |
100700 KB |
Output is correct |
10 |
Correct |
352 ms |
100700 KB |
Output is correct |
11 |
Correct |
345 ms |
100700 KB |
Output is correct |
12 |
Correct |
345 ms |
100696 KB |
Output is correct |
13 |
Correct |
349 ms |
100700 KB |
Output is correct |
14 |
Correct |
357 ms |
100648 KB |
Output is correct |
15 |
Correct |
356 ms |
100696 KB |
Output is correct |
16 |
Correct |
348 ms |
100700 KB |
Output is correct |
17 |
Correct |
356 ms |
100700 KB |
Output is correct |
18 |
Correct |
338 ms |
100700 KB |
Output is correct |
19 |
Correct |
361 ms |
100696 KB |
Output is correct |
20 |
Correct |
345 ms |
100696 KB |
Output is correct |
21 |
Correct |
356 ms |
100700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
487 ms |
100696 KB |
Output is correct |
2 |
Correct |
373 ms |
100696 KB |
Output is correct |
3 |
Correct |
473 ms |
100696 KB |
Output is correct |
4 |
Correct |
386 ms |
100700 KB |
Output is correct |
5 |
Correct |
350 ms |
100700 KB |
Output is correct |
6 |
Correct |
334 ms |
100696 KB |
Output is correct |
7 |
Correct |
353 ms |
100700 KB |
Output is correct |
8 |
Correct |
340 ms |
100700 KB |
Output is correct |
9 |
Correct |
355 ms |
100696 KB |
Output is correct |
10 |
Correct |
863 ms |
100700 KB |
Output is correct |
11 |
Correct |
792 ms |
101044 KB |
Output is correct |
12 |
Correct |
810 ms |
100700 KB |
Output is correct |
13 |
Correct |
776 ms |
100700 KB |
Output is correct |
14 |
Correct |
532 ms |
100696 KB |
Output is correct |
15 |
Correct |
441 ms |
100700 KB |
Output is correct |
16 |
Correct |
480 ms |
100700 KB |
Output is correct |
17 |
Correct |
479 ms |
100696 KB |
Output is correct |
18 |
Correct |
360 ms |
100700 KB |
Output is correct |
19 |
Correct |
393 ms |
100740 KB |
Output is correct |
20 |
Correct |
377 ms |
100696 KB |
Output is correct |
21 |
Correct |
381 ms |
100700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
275 ms |
100688 KB |
Output is correct |
2 |
Correct |
263 ms |
100596 KB |
Output is correct |
3 |
Correct |
272 ms |
100700 KB |
Output is correct |
4 |
Correct |
277 ms |
100700 KB |
Output is correct |
5 |
Correct |
281 ms |
100700 KB |
Output is correct |
6 |
Correct |
283 ms |
100968 KB |
Output is correct |
7 |
Correct |
357 ms |
100552 KB |
Output is correct |
8 |
Correct |
360 ms |
100696 KB |
Output is correct |
9 |
Correct |
319 ms |
100696 KB |
Output is correct |
10 |
Correct |
343 ms |
100696 KB |
Output is correct |
11 |
Correct |
344 ms |
100700 KB |
Output is correct |
12 |
Correct |
231 ms |
100536 KB |
Output is correct |
13 |
Correct |
52 ms |
100700 KB |
Output is correct |
14 |
Correct |
238 ms |
100696 KB |
Output is correct |
15 |
Correct |
59 ms |
100700 KB |
Output is correct |
16 |
Correct |
205 ms |
100696 KB |
Output is correct |
17 |
Correct |
347 ms |
100696 KB |
Output is correct |
18 |
Correct |
307 ms |
100952 KB |
Output is correct |
19 |
Correct |
297 ms |
100696 KB |
Output is correct |
20 |
Correct |
349 ms |
100792 KB |
Output is correct |
21 |
Correct |
382 ms |
100696 KB |
Output is correct |
22 |
Correct |
438 ms |
100700 KB |
Output is correct |
23 |
Correct |
398 ms |
100700 KB |
Output is correct |
24 |
Correct |
377 ms |
100696 KB |
Output is correct |
25 |
Correct |
593 ms |
100700 KB |
Output is correct |
26 |
Correct |
562 ms |
100720 KB |
Output is correct |
27 |
Correct |
685 ms |
100948 KB |
Output is correct |
28 |
Correct |
621 ms |
100696 KB |
Output is correct |
29 |
Correct |
466 ms |
100696 KB |
Output is correct |
30 |
Correct |
449 ms |
100700 KB |
Output is correct |
31 |
Correct |
393 ms |
100700 KB |
Output is correct |
32 |
Correct |
448 ms |
100700 KB |
Output is correct |
33 |
Correct |
823 ms |
101200 KB |
Output is correct |
34 |
Correct |
795 ms |
100764 KB |
Output is correct |
35 |
Correct |
869 ms |
100700 KB |
Output is correct |
36 |
Correct |
908 ms |
100700 KB |
Output is correct |
37 |
Correct |
113 ms |
100700 KB |
Output is correct |
38 |
Correct |
284 ms |
100700 KB |
Output is correct |
39 |
Correct |
293 ms |
100700 KB |
Output is correct |
40 |
Correct |
287 ms |
100788 KB |
Output is correct |
41 |
Correct |
270 ms |
100700 KB |
Output is correct |
42 |
Correct |
337 ms |
100700 KB |
Output is correct |
43 |
Correct |
334 ms |
100700 KB |
Output is correct |
44 |
Correct |
336 ms |
100700 KB |
Output is correct |
45 |
Correct |
344 ms |
100700 KB |
Output is correct |
46 |
Correct |
352 ms |
100700 KB |
Output is correct |
47 |
Correct |
345 ms |
100700 KB |
Output is correct |
48 |
Correct |
345 ms |
100696 KB |
Output is correct |
49 |
Correct |
349 ms |
100700 KB |
Output is correct |
50 |
Correct |
357 ms |
100648 KB |
Output is correct |
51 |
Correct |
356 ms |
100696 KB |
Output is correct |
52 |
Correct |
348 ms |
100700 KB |
Output is correct |
53 |
Correct |
356 ms |
100700 KB |
Output is correct |
54 |
Correct |
338 ms |
100700 KB |
Output is correct |
55 |
Correct |
361 ms |
100696 KB |
Output is correct |
56 |
Correct |
345 ms |
100696 KB |
Output is correct |
57 |
Correct |
356 ms |
100700 KB |
Output is correct |
58 |
Correct |
487 ms |
100696 KB |
Output is correct |
59 |
Correct |
373 ms |
100696 KB |
Output is correct |
60 |
Correct |
473 ms |
100696 KB |
Output is correct |
61 |
Correct |
386 ms |
100700 KB |
Output is correct |
62 |
Correct |
350 ms |
100700 KB |
Output is correct |
63 |
Correct |
334 ms |
100696 KB |
Output is correct |
64 |
Correct |
353 ms |
100700 KB |
Output is correct |
65 |
Correct |
340 ms |
100700 KB |
Output is correct |
66 |
Correct |
355 ms |
100696 KB |
Output is correct |
67 |
Correct |
863 ms |
100700 KB |
Output is correct |
68 |
Correct |
792 ms |
101044 KB |
Output is correct |
69 |
Correct |
810 ms |
100700 KB |
Output is correct |
70 |
Correct |
776 ms |
100700 KB |
Output is correct |
71 |
Correct |
532 ms |
100696 KB |
Output is correct |
72 |
Correct |
441 ms |
100700 KB |
Output is correct |
73 |
Correct |
480 ms |
100700 KB |
Output is correct |
74 |
Correct |
479 ms |
100696 KB |
Output is correct |
75 |
Correct |
360 ms |
100700 KB |
Output is correct |
76 |
Correct |
393 ms |
100740 KB |
Output is correct |
77 |
Correct |
377 ms |
100696 KB |
Output is correct |
78 |
Correct |
381 ms |
100700 KB |
Output is correct |
79 |
Correct |
516 ms |
100696 KB |
Output is correct |
80 |
Correct |
385 ms |
100580 KB |
Output is correct |
81 |
Correct |
358 ms |
100700 KB |
Output is correct |
82 |
Correct |
369 ms |
100696 KB |
Output is correct |
83 |
Correct |
322 ms |
100620 KB |
Output is correct |
84 |
Correct |
349 ms |
100696 KB |
Output is correct |
85 |
Correct |
378 ms |
100700 KB |
Output is correct |
86 |
Correct |
345 ms |
100956 KB |
Output is correct |
87 |
Correct |
349 ms |
100700 KB |
Output is correct |
88 |
Correct |
405 ms |
100600 KB |
Output is correct |
89 |
Correct |
638 ms |
100760 KB |
Output is correct |
90 |
Correct |
599 ms |
100552 KB |
Output is correct |
91 |
Correct |
641 ms |
100700 KB |
Output is correct |
92 |
Correct |
379 ms |
100696 KB |
Output is correct |
93 |
Correct |
383 ms |
100700 KB |
Output is correct |
94 |
Correct |
655 ms |
100696 KB |
Output is correct |
95 |
Correct |
989 ms |
100700 KB |
Output is correct |
96 |
Execution timed out |
1057 ms |
100700 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |