結果

問題 No.1085 桁和の桁和
ユーザー tonegawatonegawa
提出日時 2020-08-12 17:06:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,464 bytes
コンパイル時間 1,366 ms
コンパイル使用メモリ 120,664 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-04-24 10:12:59
合計ジャッジ時間 2,557 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 10 ms
5,376 KB
testcase_15 AC 20 ms
7,680 KB
testcase_16 AC 19 ms
7,680 KB
testcase_17 AC 10 ms
5,376 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 18 ms
7,168 KB
testcase_20 AC 8 ms
5,376 KB
testcase_21 AC 12 ms
5,888 KB
testcase_22 AC 17 ms
6,784 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 10 ms
5,632 KB
testcase_26 AC 20 ms
7,936 KB
testcase_27 AC 16 ms
7,168 KB
testcase_28 AC 22 ms
8,704 KB
testcase_29 AC 12 ms
6,016 KB
testcase_30 AC 11 ms
5,760 KB
testcase_31 AC 19 ms
7,680 KB
testcase_32 AC 13 ms
6,144 KB
testcase_33 AC 41 ms
13,440 KB
testcase_34 AC 43 ms
13,312 KB
testcase_35 AC 42 ms
13,312 KB
testcase_36 AC 40 ms
13,568 KB
testcase_37 AC 42 ms
13,312 KB
testcase_38 AC 41 ms
13,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

#define P 1000000007

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  ll d;std::cin >> d;
  ll cnt = 0, S = 0;
  ll fst = -1;

  for(int i=0;i<s.size();i++){
    if(s[i]=='?') cnt++;
    else S += (s[i] - '0');
  }

  for(ll i=0;i<=9*cnt;i++){
    ll tmp_S = S + i;
    while(tmp_S>=10){
      ll num = 0;
      while(tmp_S){
        num += tmp_S%10;
        tmp_S/=10;
      }
      tmp_S = num;
    }
    if(tmp_S==d){
      fst = i;
      break;
    }
  }

  if(fst==-1) {
    std::cout << 0 << '\n';
    return 0;
  }
  if(cnt==0) {
    std::cout << 1 << '\n';
    return 0;
  }

  vvl dp = VV(cnt+1, 9, 0, ll);//9mod
  dp[0][0] = 1;
  for(int i=0;i<cnt;i++){
    for(int j=0;j<9;j++){
      for(int k=0;k<=9;k++){
        dp[i+1][(j+k)%9] = (dp[i+1][(j+k)%9] + dp[i][j])%P;
      }
    }
  }
  std::cout << (dp[cnt][fst%9] - (fst==9?1:0) + P)%P << '\n';
  return 0;
}
0