結果

問題 No.1085 桁和の桁和
ユーザー SSRSSSRS
提出日時 2020-06-19 22:16:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 910 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 169,924 KB
実行使用メモリ 13,584 KB
最終ジャッジ日時 2023-09-30 06:15:23
合計ジャッジ時間 3,852 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 22 ms
6,708 KB
testcase_15 AC 51 ms
11,736 KB
testcase_16 AC 51 ms
11,876 KB
testcase_17 AC 24 ms
7,088 KB
testcase_18 AC 13 ms
5,156 KB
testcase_19 AC 48 ms
10,704 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 33 ms
8,148 KB
testcase_22 AC 46 ms
10,156 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 26 ms
7,584 KB
testcase_26 AC 52 ms
11,984 KB
testcase_27 AC 42 ms
10,192 KB
testcase_28 AC 58 ms
13,340 KB
testcase_29 AC 34 ms
8,288 KB
testcase_30 AC 31 ms
8,056 KB
testcase_31 AC 54 ms
11,784 KB
testcase_32 AC 34 ms
8,852 KB
testcase_33 AC 100 ms
13,288 KB
testcase_34 AC 102 ms
13,360 KB
testcase_35 AC 103 ms
13,368 KB
testcase_36 AC 107 ms
13,340 KB
testcase_37 AC 104 ms
13,584 KB
testcase_38 AC 106 ms
13,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
int main(){
  string T;
  cin >> T;
  int D;
  cin >> D;
  int N = T.size();
  if (D == 0){
    bool zero = true;
    for (int i = 0; i < N; i++){
      if (T[i] != '0' && T[i] != '?'){
        zero = false;
      }
    }
    if (zero){
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    vector<vector<long long>> dp(N + 1, vector<long long>(9, 0));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++){
      if (T[i] == '?'){
        for (int j = 0; j < 9; j++){
          for (int k = 0; k <= 9; k++){
            dp[i + 1][(j + k) % 9] += dp[i][j];
            dp[i + 1][(j + k) % 9] %= MOD;
          }
        }
      } else {
        int d = T[i] - '0';
        for (int j = 0; j < 9; j++){
          dp[i + 1][(j + d) % 9] = dp[i][j];
        }
      }
    }
    cout << dp[N][D % 9] << endl;
  }
}
0