結果
| 問題 | No.1085 桁和の桁和 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-06-19 22:29:40 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 49 ms / 2,000 ms | 
| コード長 | 1,449 bytes | 
| コンパイル時間 | 1,758 ms | 
| コンパイル使用メモリ | 172,332 KB | 
| 実行使用メモリ | 13,568 KB | 
| 最終ジャッジ日時 | 2024-11-06 17:38:26 | 
| 合計ジャッジ時間 | 3,512 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 35 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int main(){
    string t;
    cin >> t;
    int d;
    cin >> d;
    int n = t.size();
    bool zero = true;
    if(d==0){
        rep(i,n){
            if('1' <= t[i] && t[i] <= '9') zero = false;
        }
        if(zero) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    rep(i,n){
            if('1' <= t[i] && t[i] <= '9') zero = false;
    }
    vector<vector<ll>> dp(n+1,vector<ll>(9,0));
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        bool q = false;
        int td = t[i] - '0';
        if(td < 0 || 9 < td) q = true;
        if(!q){
            for(int j=0;j<9;j++){
                dp[i+1][(10*j+td)%9] += dp[i][j];
                dp[i+1][(10*j+td)%9] %= MOD;
            }
        }else{
             for(int j=0;j<9;j++){
                 rep(k,10){
                    dp[i+1][(10*j+k)%9] += dp[i][j];
                    dp[i+1][(10*j+k)%9] %= MOD;
                 }
            }
        }
    }
    if(d==9){
        ll ans = dp[n][0];
        if(zero) cout << ans-1 << endl;
        else cout << ans << endl;
    }else{
        cout << dp[n][d] << endl;
    }
    return 0;
}
            
            
            
        