답안 #53808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53808 2018-07-01T08:37:02 Z ruhanhabib39 Bowling (BOI15_bow) C++17
26 / 100
3 ms 1000 KB
#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

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]);
          ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 756 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 3 ms 764 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 2 ms 772 KB Output is correct
10 Correct 2 ms 780 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
12 Correct 2 ms 788 KB Output is correct
13 Correct 2 ms 888 KB Output is correct
14 Correct 2 ms 888 KB Output is correct
15 Correct 2 ms 888 KB Output is correct
16 Correct 2 ms 888 KB Output is correct
17 Correct 2 ms 888 KB Output is correct
18 Correct 2 ms 888 KB Output is correct
19 Correct 2 ms 888 KB Output is correct
20 Correct 2 ms 1000 KB Output is correct
21 Correct 2 ms 1000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -