#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 12
#define MAXSCORE 300
#define INF 1e9+7
using namespace std;
ll q,n;
ll dp[N][MAXSCORE][3],ar[N]; // 0 -> normal , 1 -> spare , 2-> strike
string s;
ll calculate(ll round,ll score,ll type)
{
char p1 = s[2*(round-1)];
char p2 = s[2*(round-1)+1];
ll res = 0;
if(p1 == 'x')
{
if(type == 2)
{
}
else
return 0;
}
else if(p2 == '/')
{
if(type == 1)
{
}
else
return 0;
}
else if(p1 == '?' && p2 == '?')
{
if(type == 0)
{
rep(a,0,10)
{
rep(b,0,10)
{
if(a+b >= 10 || a+b > score)
break;
res += dp[round-1][score-a-b][0];
if(2*a+b > score)
continue;
res += dp[round-1][score-2*a-b][1];
if(2*a+2*b > score)
continue;
res += dp[round-1][score-2*a-2*b][2];
}
}
}
else if(type == 1)
{
}
else if(type == 2)
{
}
}
else if(p1 == '?')
{
if(type == 0)
{
ll b = p2-'0';
rep(a,0,10)
{
if(a+b >= 10 || a+b > score)
break;
res += dp[round-1][score-a-b][0];
if(2*a+b > score)
continue;
res += dp[round-1][score-2*a-b][1];
if(2*a+2*b > score)
continue;
res += dp[round-1][score-2*a-2*b][2];
}
return res;
}
else if(type == 1)
{
return 0;
}
else
return 0;
}
else if(p2 == '?')
{
if(type == 0)
{
ll a = p1-'0';
rep(b,0,10)
{
if(a+b >= 10 || a+b > score)
break;
res += dp[round-1][score-a-b][0];
if(2*a+b > score)
continue;
res += dp[round-1][score-2*a-b][1];
if(2*a+2*b > score)
continue;
res += dp[round-1][score-2*a-2*b][2];
}
return res;
}
else if(type == 1)
{
}
else
return 0;
}
else
{
if(type == 0)
{
ll a = p1-'0';
ll b = p2 - '0';
if(a+b < 10 && a+b<=score)
res += dp[round-1][score-a-b][0];
if(2*a+b <= score)
res += dp[round-1][score-2*a-b][1];
if(2*a+2*b <= score)
res += dp[round-1][score-2*a-2*b][2];
return res;
}
else
{
return 0;
}
}
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> q;
while(q--)
{
cin >> n;
cin >> s;
rep(i,0,s.size()-3)
{
if(s[i] == '-')
s[i-1] = 'x';
if(s[i] == 'x')
s[i-1] = '-';
}
rep(i,1,n+1)
{
cin >> ar[i];
}
memset(dp,0,sizeof dp);
dp[0][0][0] = 1;
rep(i,1,n)
{
rep(j,0,MAXSCORE)
{
rep(k,0,3)
{
if(ar[i] == -1 || ar[i] == j)
dp[i][j][k] = calculate(i,j,k);
else
dp[i][j][k] = 0;
}
}
// ll x;
// cin >> x;
// cout << dp[i][ar[i]][0] << " ";
}
// cout << endl;
ll ans = 0;
if(ar[n] == -1)
{
rep(j,0,MAXSCORE)
ans += calculate(n,j,0)+calculate(n,j,1)+calculate(n,j,2);
}
else
{
ans = calculate(n,ar[n],0)+calculate(n,ar[n],1)+calculate(n,ar[n],2);
}
cout << ans << "\n";
}
return 0;
}
Compilation message
bow.cpp: In function 'int main()':
bow.cpp:13:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i,a,b) for(int i = a;i < b;i++)
bow.cpp:188:13:
rep(i,0,s.size()-3)
~~~~~~~~~~~~~~
bow.cpp:188:9: note: in expansion of macro 'rep'
rep(i,0,s.size()-3)
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
888 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
632 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
380 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Correct |
4 ms |
376 KB |
Output is correct |
16 |
Correct |
4 ms |
504 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
380 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
888 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |