結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 22 ms
6,764 KB
testcase_15 AC 51 ms
11,724 KB
testcase_16 AC 50 ms
11,740 KB
testcase_17 AC 24 ms
7,104 KB
testcase_18 AC 13 ms
5,164 KB
testcase_19 AC 48 ms
10,652 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 29 ms
8,028 KB
testcase_22 AC 42 ms
10,192 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 28 ms
7,500 KB
testcase_26 AC 53 ms
12,204 KB
testcase_27 AC 41 ms
10,124 KB
testcase_28 AC 59 ms
13,232 KB
testcase_29 AC 31 ms
8,332 KB
testcase_30 AC 28 ms
7,984 KB
testcase_31 AC 52 ms
11,848 KB
testcase_32 AC 35 ms
8,772 KB
testcase_33 AC 101 ms
13,520 KB
testcase_34 AC 102 ms
13,312 KB
testcase_35 AC 102 ms
13,292 KB
testcase_36 AC 101 ms
13,308 KB
testcase_37 AC 101 ms
13,272 KB
testcase_38 AC 104 ms
13,308 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();
  bool zero = true;
  for (int i = 0; i < N; i++){
    if (T[i] != '0' && T[i] != '?'){
      zero = false;
    }
  }
  if (zero){
    if (D == 0){
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else if (D == 0){
    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