結果

問題 No.1085 桁和の桁和
ユーザー HaarHaar
提出日時 2020-06-19 22:25:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,980 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 205,356 KB
実行使用メモリ 13,404 KB
最終ジャッジ日時 2023-09-30 06:17:29
合計ジャッジ時間 4,060 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 11 ms
6,804 KB
testcase_15 AC 23 ms
11,672 KB
testcase_16 AC 22 ms
11,736 KB
testcase_17 AC 11 ms
6,944 KB
testcase_18 AC 7 ms
5,204 KB
testcase_19 AC 20 ms
10,624 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 13 ms
8,068 KB
testcase_22 AC 19 ms
10,176 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 12 ms
7,472 KB
testcase_26 AC 23 ms
12,084 KB
testcase_27 AC 19 ms
10,232 KB
testcase_28 AC 26 ms
13,404 KB
testcase_29 AC 15 ms
8,308 KB
testcase_30 AC 13 ms
8,124 KB
testcase_31 AC 23 ms
11,776 KB
testcase_32 AC 16 ms
8,860 KB
testcase_33 AC 32 ms
13,320 KB
testcase_34 AC 33 ms
13,392 KB
testcase_35 AC 32 ms
13,388 KB
testcase_36 AC 33 ms
13,396 KB
testcase_37 AC 33 ms
13,404 KB
testcase_38 AC 31 ms
13,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

/**
 * @title Modint
 * @docs mint.md
 */
template <uint32_t M> class ModInt{
public:
  constexpr static uint32_t MOD = M;
  uint64_t val;
  
  constexpr ModInt(): val(0){}
  constexpr ModInt(int64_t n){
    if(n >= M) val = n % M;
    else if(n < 0) val = n % M + M;
    else val = n;
  }
  
  inline constexpr auto operator+(const ModInt &a) const {return ModInt(val + a.val);}
  inline constexpr auto operator-(const ModInt &a) const {return ModInt(val - a.val);}
  inline constexpr auto operator*(const ModInt &a) const {return ModInt(val * a.val);}
  inline constexpr auto operator/(const ModInt &a) const {return ModInt(val * a.inv().val);}
  
  inline constexpr auto& operator=(const ModInt &a){val = a.val; return *this;}
  inline constexpr auto& operator+=(const ModInt &a){if((val += a.val) >= M) val -= M; return *this;}
  inline constexpr auto& operator-=(const ModInt &a){if(val < a.val) val += M; val -= a.val; return *this;}
  inline constexpr auto& operator*=(const ModInt &a){(val *= a.val) %= M; return *this;}
  inline constexpr auto& operator/=(const ModInt &a){(val *= a.inv().val) %= M; return *this;}
  
  inline constexpr bool operator==(const ModInt &a) const {return val == a.val;}
  inline constexpr bool operator!=(const ModInt &a) const {return val != a.val;}
  
  inline constexpr auto& operator++(){*this += 1; return *this;}
  inline constexpr auto& operator--(){*this -= 1; return *this;}
  
  inline constexpr auto operator++(int){auto t = *this; *this += 1; return t;}
  inline constexpr auto operator--(int){auto t = *this; *this -= 1; return t;}
  
  inline constexpr static ModInt power(int64_t n, int64_t p){
    if(p < 0) return power(n, -p).inv();
    
    int64_t ret = 1, e = n % M;
    for(; p; (e *= e) %= M, p >>= 1) if(p & 1) (ret *= e) %= M;
    return ret;
  }
  
  inline constexpr static ModInt inv(int64_t a){
    int64_t b = M, u = 1, v = 0;
    
    while(b){
      int64_t t = a / b;
      a -= t * b; std::swap(a,b);
      u -= t * v; std::swap(u,v);
    }
    
    u %= M;
    if(u < 0) u += M;
    
    return u;
  }
  
  inline constexpr static auto frac(int64_t a, int64_t b){return ModInt(a) / ModInt(b);}
  
  inline constexpr auto power(int64_t p) const {return power(val, p);}
  inline constexpr auto inv() const {return inv(val);}
  
  friend inline constexpr auto operator-(const ModInt &a){return ModInt(-a.val);}
  
  friend inline constexpr auto operator+(int64_t a, const ModInt &b){return ModInt(a) + b;}
  friend inline constexpr auto operator-(int64_t a, const ModInt &b){return ModInt(a) - b;}
  friend inline constexpr auto operator*(int64_t a, const ModInt &b){return ModInt(a) * b;}
  friend inline constexpr auto operator/(int64_t a, const ModInt &b){return ModInt(a) / b;}
  
  friend std::istream& operator>>(std::istream &s, ModInt<M> &a){s >> a.val; return s;}
  friend std::ostream& operator<<(std::ostream &s, const ModInt<M> &a){s << a.val; return s;}

  template <int N>
  inline static auto div(){
    static auto value = inv(N);
    return value;
  }

  explicit operator int32_t() const noexcept {return val;}
  explicit operator int64_t() const noexcept {return val;}
};

using mint = ModInt<1000000007>;


int main(){
  std::string T;
  int D;

  while(std::cin >> T >> D){
    const int N = T.size();

    mint ans = 0;

    if(D == 0){
      if(std::all_of(T.begin(), T.end(), [](char a){return a == '0' or a == '?';})){
        ans = 1;
      }
    }else{

      auto dp = std::vector(N + 1, std::vector<mint>(9));

      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 < 10; ++k){
              dp[i+1][(j+k)%9] += dp[i][j];
            }
          }
        }else{
          for(int j = 0; j < 9; ++j){
            dp[i+1][(j+T[i]-'0')%9] += dp[i][j];
          }
        }
      }

      ans = dp[N][D % 9];
    }

    std::cout << ans << "\n";
  }

  return 0;
}
0