結果

問題 No.1085 桁和の桁和
ユーザー KKT89KKT89
提出日時 2020-06-19 22:16:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,253 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 99,996 KB
実行使用メモリ 11,496 KB
最終ジャッジ日時 2023-08-06 14:29:43
合計ジャッジ時間 2,859 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 10 ms
4,956 KB
testcase_15 AC 19 ms
7,016 KB
testcase_16 AC 18 ms
7,052 KB
testcase_17 AC 10 ms
5,068 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 17 ms
6,452 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 12 ms
5,496 KB
testcase_22 AC 16 ms
6,204 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 11 ms
5,152 KB
testcase_26 AC 19 ms
7,056 KB
testcase_27 AC 16 ms
6,244 KB
testcase_28 AC 21 ms
7,396 KB
testcase_29 AC 13 ms
5,536 KB
testcase_30 AC 12 ms
5,536 KB
testcase_31 AC 19 ms
6,908 KB
testcase_32 AC 13 ms
5,800 KB
testcase_33 AC 40 ms
11,296 KB
testcase_34 AC 40 ms
11,300 KB
testcase_35 AC 40 ms
11,496 KB
testcase_36 AC 41 ms
11,288 KB
testcase_37 AC 40 ms
11,228 KB
testcase_38 AC 40 ms
11,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <deque>
#include <cstdio>
#include <queue>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const ll mx=1e9;
constexpr ll mod=1e9+7;

ll mod_pow(ll a,ll b){
    a%=mod;
    if(b==0)return 1;
    if(b==1)return a;
    ll res=mod_pow(a,b/2)%mod;
    res*=res; res%=mod;
    if(b%2)res*=a;
    return res%mod;
}

int cal(int s){
    if(s==0)return 0;
    s--;
    return s%9+1;
}

ll dp[100100][10];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string t; cin >> t;
    int d; cin >> d;
    if(d==0){
        bool ok=1;
        for(char c:t){
            if(c=='?'||c=='0'){

            }
            else{
                ok=0;
            }
        }
        cout << ok << endl;
        return 0;
    }
    int cnt=0;
    int sum=0;
    for(char c:t){
        if(c=='?')cnt++;
        else sum+=(c-'0');
    }
    sum=cal(sum);
    dp[0][sum]=1LL;
    for(int i=0;i<cnt;i++){
        for(int j=0;j<=9;j++){
            for(int k=0;k<=9;k++){
                (dp[i+1][cal(k+j)]+=dp[i][k])%=mod;
            }
        }
    }
    cout << dp[cnt][d] << endl;
}
0