#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll t,n,sl,has,d[11][310][11][11],x[1010],i,a[1010][3];
string s;
ll con(char aa)
{
if('0'<=aa&&aa<='9')
return (aa-'0');
if(aa=='-')
return 12;
if(aa=='x')
return 10;
if(aa=='/')
return 11;
if(aa=='?')
return -1;
}
void ubah()
{
ll ii,jj;
for(ii=1;ii<=n;ii++)
for(jj=1;jj<=2;jj++)
{
a[ii][jj]=con(s[(ii-1)*2+(jj-1)]);
}
a[n][3]=con(s[sl-1]);
}
ll depe(ll aa,ll bb,ll cc,ll dd)
{
if(aa==0&&bb==0)return 1;
if(aa==0||bb<0)return 0;
if(x[aa]!=-1&&x[aa]!=bb)return 0;
if(d[aa][bb][cc][dd]==-1)
{
d[aa][bb][cc][dd]=0;
if(aa==n)
{
ll ii,jj;
if((a[aa][1]==10||a[aa][1]==-1)&&(a[aa][2]==10||a[aa][2]==-1)&&(a[aa][3]==10||a[aa][3]==-1))
d[aa][bb][cc][dd]+=depe(aa-1,bb-30,10,10);
for(ii=0;ii<=9;ii++)
{
if((a[aa][1]==10||a[aa][1]==-1)&&(a[aa][2]==10||a[aa][2]==-1)&&(a[aa][3]==ii||a[aa][3]==-1))
d[aa][bb][cc][dd]+=depe(aa-1,bb-(20+ii),10,10);
if((a[aa][1]==10||a[aa][1]==-1)&&(a[aa][2]==ii||a[aa][2]==-1)&&(a[aa][3]==11||a[aa][3]==-1))
d[aa][bb][cc][dd]+=depe(aa-1,bb-20,10,ii);
if((a[aa][1]==ii||a[aa][1]==-1)&&(a[aa][2]==11||a[aa][2]==-1)&&(a[aa][3]==10||a[aa][3]==-1))
d[aa][bb][cc][dd]+=depe(aa-1,bb-20,ii,10-ii);
for(jj=0;jj<=9;jj++)
{
if((a[aa][1]==ii||a[aa][1]==-1)&&(a[aa][2]==11||a[aa][2]==-1)&&(a[aa][3]==jj||a[aa][3]==-1))
d[aa][bb][cc][dd]+=depe(aa-1,bb-(10+jj),ii,10-ii);
if((ii+jj)<10)
{
if((a[aa][1]==10||a[aa][1]==-1)&&(a[aa][2]==ii||a[aa][2]==-1)&&(a[aa][3]==jj||a[aa][3]==-1))
d[aa][bb][cc][dd]+=depe(aa-1,bb-(10+ii+jj),10,ii);
if((a[aa][1]==ii||a[aa][1]==-1)&&(a[aa][2]==jj||a[aa][2]==-1)&&(a[aa][3]==12||a[aa][3]==-1))
d[aa][bb][cc][dd]+=depe(aa-1,bb-(ii+jj),ii,jj);
}
}
}
}
else
{
ll ii,jj;
for(ii=0;ii<=9;ii++)
for(jj=0;jj<=9;jj++)
if((ii+jj)<10)
{
if((a[aa][1]==ii||a[aa][1]==-1)&&(a[aa][2]==jj||a[aa][2]==-1))
{
d[aa][bb][cc][dd]+=depe(aa-1,bb-(ii+jj),ii,jj);
}
}
if((a[aa][1]==10||a[aa][1]==-1)&&(a[aa][2]==12||a[aa][2]==-1))
{
d[aa][bb][cc][dd]+=depe(aa-1,bb-(10+cc+dd),10,cc);
}
for(ii=0;ii<=9;ii++)
{
if((a[aa][1]==ii||a[aa][1]==-1)&&(a[aa][2]==11||a[aa][2]==-1))
{
d[aa][bb][cc][dd]+=depe(aa-1,bb-(10+cc),ii,10-ii);
}
}
}
}
return d[aa][bb][cc][dd];
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>t;
while(t--)
{
has=0;
cin>>n;
cin>>s;
sl=s.length();
for(i=1;i<=n;i++)
cin>>x[i];
ubah();
memset(d,-1,sizeof(d));
has=0;
for(i=0;i<=300;i++)
has+=depe(n,i,0,0);
cout<<has<<"\n";
}
}
Compilation message
bow.cpp: In function 'll con(char)':
bow.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
bow.cpp: In function 'void ubah()':
bow.cpp:31:8: warning: array subscript is above array bounds [-Warray-bounds]
a[n][3]=con(s[sl-1]);
~~~~~~^
bow.cpp: In function 'll depe(ll, ll, ll, ll)':
bow.cpp:44:75: warning: array subscript is above array bounds [-Warray-bounds]
if((a[aa][1]==10||a[aa][1]==-1)&&(a[aa][2]==10||a[aa][2]==-1)&&(a[aa][3]==10||a[aa][3]==-1))
~~~~~~~^
bow.cpp:48:76: warning: array subscript is above array bounds [-Warray-bounds]
if((a[aa][1]==10||a[aa][1]==-1)&&(a[aa][2]==10||a[aa][2]==-1)&&(a[aa][3]==ii||a[aa][3]==-1))
~~~~~~~^
bow.cpp:50:76: warning: array subscript is above array bounds [-Warray-bounds]
if((a[aa][1]==10||a[aa][1]==-1)&&(a[aa][2]==ii||a[aa][2]==-1)&&(a[aa][3]==11||a[aa][3]==-1))
~~~~~~~^
bow.cpp:52:76: warning: array subscript is above array bounds [-Warray-bounds]
if((a[aa][1]==ii||a[aa][1]==-1)&&(a[aa][2]==11||a[aa][2]==-1)&&(a[aa][3]==10||a[aa][3]==-1))
~~~~~~~^
bow.cpp:56:77: warning: array subscript is above array bounds [-Warray-bounds]
if((a[aa][1]==ii||a[aa][1]==-1)&&(a[aa][2]==11||a[aa][2]==-1)&&(a[aa][3]==jj||a[aa][3]==-1))
~~~~~~~^
bow.cpp:60:78: warning: array subscript is above array bounds [-Warray-bounds]
if((a[aa][1]==10||a[aa][1]==-1)&&(a[aa][2]==ii||a[aa][2]==-1)&&(a[aa][3]==jj||a[aa][3]==-1))
~~~~~~~^
bow.cpp:62:78: warning: array subscript is above array bounds [-Warray-bounds]
if((a[aa][1]==ii||a[aa][1]==-1)&&(a[aa][2]==jj||a[aa][2]==-1)&&(a[aa][3]==12||a[aa][3]==-1))
~~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
3576 KB |
Output is correct |
2 |
Correct |
14 ms |
3576 KB |
Output is correct |
3 |
Correct |
9 ms |
3576 KB |
Output is correct |
4 |
Correct |
12 ms |
3704 KB |
Output is correct |
5 |
Correct |
10 ms |
3576 KB |
Output is correct |
6 |
Correct |
9 ms |
3576 KB |
Output is correct |
7 |
Correct |
85 ms |
3576 KB |
Output is correct |
8 |
Correct |
66 ms |
3612 KB |
Output is correct |
9 |
Correct |
60 ms |
3704 KB |
Output is correct |
10 |
Correct |
56 ms |
3576 KB |
Output is correct |
11 |
Correct |
12 ms |
3576 KB |
Output is correct |
12 |
Correct |
11 ms |
3576 KB |
Output is correct |
13 |
Correct |
6 ms |
3576 KB |
Output is correct |
14 |
Correct |
12 ms |
3580 KB |
Output is correct |
15 |
Correct |
7 ms |
3576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
3576 KB |
Output is correct |
2 |
Correct |
75 ms |
3576 KB |
Output is correct |
3 |
Correct |
73 ms |
3732 KB |
Output is correct |
4 |
Correct |
33 ms |
3576 KB |
Output is correct |
5 |
Correct |
80 ms |
3704 KB |
Output is correct |
6 |
Correct |
39 ms |
3576 KB |
Output is correct |
7 |
Correct |
80 ms |
3576 KB |
Output is correct |
8 |
Correct |
60 ms |
3576 KB |
Output is correct |
9 |
Correct |
39 ms |
3612 KB |
Output is correct |
10 |
Correct |
183 ms |
3652 KB |
Output is correct |
11 |
Correct |
212 ms |
3704 KB |
Output is correct |
12 |
Correct |
256 ms |
3704 KB |
Output is correct |
13 |
Correct |
226 ms |
3576 KB |
Output is correct |
14 |
Correct |
77 ms |
3652 KB |
Output is correct |
15 |
Correct |
81 ms |
3580 KB |
Output is correct |
16 |
Correct |
46 ms |
3576 KB |
Output is correct |
17 |
Correct |
62 ms |
3576 KB |
Output is correct |
18 |
Correct |
337 ms |
3704 KB |
Output is correct |
19 |
Correct |
353 ms |
3576 KB |
Output is correct |
20 |
Correct |
348 ms |
3576 KB |
Output is correct |
21 |
Correct |
412 ms |
3704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
3704 KB |
Output is correct |
2 |
Correct |
11 ms |
3576 KB |
Output is correct |
3 |
Correct |
11 ms |
3576 KB |
Output is correct |
4 |
Correct |
14 ms |
3576 KB |
Output is correct |
5 |
Correct |
10 ms |
3580 KB |
Output is correct |
6 |
Correct |
9 ms |
3576 KB |
Output is correct |
7 |
Correct |
10 ms |
3576 KB |
Output is correct |
8 |
Correct |
10 ms |
3576 KB |
Output is correct |
9 |
Correct |
10 ms |
3576 KB |
Output is correct |
10 |
Correct |
12 ms |
3576 KB |
Output is correct |
11 |
Correct |
11 ms |
3576 KB |
Output is correct |
12 |
Correct |
12 ms |
3576 KB |
Output is correct |
13 |
Correct |
11 ms |
3576 KB |
Output is correct |
14 |
Correct |
16 ms |
3576 KB |
Output is correct |
15 |
Correct |
16 ms |
3576 KB |
Output is correct |
16 |
Correct |
14 ms |
3576 KB |
Output is correct |
17 |
Correct |
18 ms |
3580 KB |
Output is correct |
18 |
Correct |
10 ms |
3576 KB |
Output is correct |
19 |
Correct |
11 ms |
3576 KB |
Output is correct |
20 |
Correct |
10 ms |
3576 KB |
Output is correct |
21 |
Correct |
12 ms |
3576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
346 ms |
3740 KB |
Output is correct |
2 |
Correct |
219 ms |
3616 KB |
Output is correct |
3 |
Correct |
339 ms |
3704 KB |
Output is correct |
4 |
Correct |
286 ms |
3576 KB |
Output is correct |
5 |
Correct |
209 ms |
3704 KB |
Output is correct |
6 |
Correct |
155 ms |
3576 KB |
Output is correct |
7 |
Correct |
223 ms |
3576 KB |
Output is correct |
8 |
Correct |
174 ms |
3612 KB |
Output is correct |
9 |
Correct |
212 ms |
3616 KB |
Output is correct |
10 |
Execution timed out |
1071 ms |
3704 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
3576 KB |
Output is correct |
2 |
Correct |
14 ms |
3576 KB |
Output is correct |
3 |
Correct |
9 ms |
3576 KB |
Output is correct |
4 |
Correct |
12 ms |
3704 KB |
Output is correct |
5 |
Correct |
10 ms |
3576 KB |
Output is correct |
6 |
Correct |
9 ms |
3576 KB |
Output is correct |
7 |
Correct |
85 ms |
3576 KB |
Output is correct |
8 |
Correct |
66 ms |
3612 KB |
Output is correct |
9 |
Correct |
60 ms |
3704 KB |
Output is correct |
10 |
Correct |
56 ms |
3576 KB |
Output is correct |
11 |
Correct |
12 ms |
3576 KB |
Output is correct |
12 |
Correct |
11 ms |
3576 KB |
Output is correct |
13 |
Correct |
6 ms |
3576 KB |
Output is correct |
14 |
Correct |
12 ms |
3580 KB |
Output is correct |
15 |
Correct |
7 ms |
3576 KB |
Output is correct |
16 |
Correct |
31 ms |
3576 KB |
Output is correct |
17 |
Correct |
75 ms |
3576 KB |
Output is correct |
18 |
Correct |
73 ms |
3732 KB |
Output is correct |
19 |
Correct |
33 ms |
3576 KB |
Output is correct |
20 |
Correct |
80 ms |
3704 KB |
Output is correct |
21 |
Correct |
39 ms |
3576 KB |
Output is correct |
22 |
Correct |
80 ms |
3576 KB |
Output is correct |
23 |
Correct |
60 ms |
3576 KB |
Output is correct |
24 |
Correct |
39 ms |
3612 KB |
Output is correct |
25 |
Correct |
183 ms |
3652 KB |
Output is correct |
26 |
Correct |
212 ms |
3704 KB |
Output is correct |
27 |
Correct |
256 ms |
3704 KB |
Output is correct |
28 |
Correct |
226 ms |
3576 KB |
Output is correct |
29 |
Correct |
77 ms |
3652 KB |
Output is correct |
30 |
Correct |
81 ms |
3580 KB |
Output is correct |
31 |
Correct |
46 ms |
3576 KB |
Output is correct |
32 |
Correct |
62 ms |
3576 KB |
Output is correct |
33 |
Correct |
337 ms |
3704 KB |
Output is correct |
34 |
Correct |
353 ms |
3576 KB |
Output is correct |
35 |
Correct |
348 ms |
3576 KB |
Output is correct |
36 |
Correct |
412 ms |
3704 KB |
Output is correct |
37 |
Correct |
12 ms |
3704 KB |
Output is correct |
38 |
Correct |
11 ms |
3576 KB |
Output is correct |
39 |
Correct |
11 ms |
3576 KB |
Output is correct |
40 |
Correct |
14 ms |
3576 KB |
Output is correct |
41 |
Correct |
10 ms |
3580 KB |
Output is correct |
42 |
Correct |
9 ms |
3576 KB |
Output is correct |
43 |
Correct |
10 ms |
3576 KB |
Output is correct |
44 |
Correct |
10 ms |
3576 KB |
Output is correct |
45 |
Correct |
10 ms |
3576 KB |
Output is correct |
46 |
Correct |
12 ms |
3576 KB |
Output is correct |
47 |
Correct |
11 ms |
3576 KB |
Output is correct |
48 |
Correct |
12 ms |
3576 KB |
Output is correct |
49 |
Correct |
11 ms |
3576 KB |
Output is correct |
50 |
Correct |
16 ms |
3576 KB |
Output is correct |
51 |
Correct |
16 ms |
3576 KB |
Output is correct |
52 |
Correct |
14 ms |
3576 KB |
Output is correct |
53 |
Correct |
18 ms |
3580 KB |
Output is correct |
54 |
Correct |
10 ms |
3576 KB |
Output is correct |
55 |
Correct |
11 ms |
3576 KB |
Output is correct |
56 |
Correct |
10 ms |
3576 KB |
Output is correct |
57 |
Correct |
12 ms |
3576 KB |
Output is correct |
58 |
Correct |
346 ms |
3740 KB |
Output is correct |
59 |
Correct |
219 ms |
3616 KB |
Output is correct |
60 |
Correct |
339 ms |
3704 KB |
Output is correct |
61 |
Correct |
286 ms |
3576 KB |
Output is correct |
62 |
Correct |
209 ms |
3704 KB |
Output is correct |
63 |
Correct |
155 ms |
3576 KB |
Output is correct |
64 |
Correct |
223 ms |
3576 KB |
Output is correct |
65 |
Correct |
174 ms |
3612 KB |
Output is correct |
66 |
Correct |
212 ms |
3616 KB |
Output is correct |
67 |
Execution timed out |
1071 ms |
3704 KB |
Time limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |