結果

問題 No.1085 桁和の桁和
ユーザー tonegawatonegawa
提出日時 2020-08-12 17:04:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,466 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 120,732 KB
実行使用メモリ 13,604 KB
最終ジャッジ日時 2023-09-30 06:33:27
合計ジャッジ時間 3,362 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 10 ms
4,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

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