Submission #53808

#TimeUsernameProblemLanguageResultExecution timeMemory
53808ruhanhabib39Bowling (BOI15_bow)C++17
26 / 100
3 ms1000 KiB
#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)

bow.cpp: In function 'int main()':
bow.cpp:31:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int q; scanf("%d", &q);
           ~~~~~^~~~~~~~~~
bow.cpp:33:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d%s", &n, match);
       ~~~~~^~~~~~~~~~~~~~~~~~~
bow.cpp:35:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
          scanf("%d", &sum[i]);
          ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...