# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
53808 | ruhanhabib39 | Bowling (BOI15_bow) | C++17 | 3 ms | 1000 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n;
char match[2 * 10 + 10];
int sum[2 * 10 + 10];
long long dp[15][10 * 30 + 10];
long long calc(int i, int s) {
if(dp[i][s] != -1) return dp[i][s];
dp[i][s] = 0;
if(i > 0 && sum[i-1] != -1 && s != sum[i-1]) return 0;
if(i == n) return dp[i][s] = 1;
if(match[2*i] != '?' && match[2*i+1] != '?') {
assert(isdigit(match[2*i]) && isdigit(match[2*i+1]));
return dp[i][s] = calc(i+1, s + int(match[2*i] - '0') + int(match[2*i+1] - '0'));
}
bool both = match[2*i] == '?' && match[2*i+1] == '?';
int x = 0;
if(match[2*i] != '?') x = int(match[2*i] - '0');
else if(match[2*i+1] != '?') x = int(match[2*i+1] - '0');
for(; x < 10; x++) {
if(both) dp[i][s] += calc(i+1, s+x) * (x + 1);
else dp[i][s] += calc(i+1, s+x);
}
return dp[i][s];
}
int main() {
int q; scanf("%d", &q);
for(int t = 0; t < q; t++) {
scanf("%d%s", &n, match);
for(int i = 0; i < n; i++) {
scanf("%d", &sum[i]);
}
memset(dp, -1, sizeof dp);
if(count(match, match + 2*n + 1, 'x') || count(match, match + 2*n + 1, '/')) printf("0\n");
else printf("%lld\n", calc(0, 0));
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |