結果

問題 No.1085 桁和の桁和
ユーザー tonegawatonegawa
提出日時 2020-08-12 17:05:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,466 bytes
コンパイル時間 1,153 ms
コンパイル使用メモリ 116,972 KB
最終ジャッジ日時 2025-01-12 21:27:27
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 5 WA * 30
権限があれば一括ダウンロードができます

ソースコード

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