結果

問題 No.1085 桁和の桁和
ユーザー tonegawatonegawa
提出日時 2020-08-12 16:58:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,438 bytes
コンパイル時間 1,105 ms
コンパイル使用メモリ 119,872 KB
実行使用メモリ 13,264 KB
最終ジャッジ日時 2023-09-30 06:33:24
合計ジャッジ時間 2,742 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 9 ms
4,840 KB
testcase_15 AC 20 ms
7,544 KB
testcase_16 AC 20 ms
7,228 KB
testcase_17 AC 9 ms
5,164 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 18 ms
6,968 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 12 ms
5,428 KB
testcase_22 AC 16 ms
6,968 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 11 ms
5,160 KB
testcase_26 AC 21 ms
7,760 KB
testcase_27 AC 17 ms
6,752 KB
testcase_28 AC 23 ms
8,292 KB
testcase_29 AC 13 ms
5,724 KB
testcase_30 AC 13 ms
5,384 KB
testcase_31 AC 22 ms
7,588 KB
testcase_32 AC 14 ms
5,956 KB
testcase_33 AC 43 ms
13,040 KB
testcase_34 AC 43 ms
13,264 KB
testcase_35 AC 42 ms
13,068 KB
testcase_36 AC 44 ms
13,120 KB
testcase_37 AC 43 ms
13,080 KB
testcase_38 AC 42 ms
13,088 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] << '\n';
  return 0;
}
0