結果

問題 No.1085 桁和の桁和
ユーザー DriceDrice
提出日時 2020-06-20 20:38:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 34,688 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-24 10:09:47
合計ジャッジ時間 1,653 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 20 ms
7,168 KB
testcase_16 AC 19 ms
7,040 KB
testcase_17 AC 10 ms
5,376 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 17 ms
6,784 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 11 ms
5,760 KB
testcase_22 AC 16 ms
6,528 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 9 ms
5,504 KB
testcase_26 AC 18 ms
7,168 KB
testcase_27 AC 17 ms
6,656 KB
testcase_28 AC 21 ms
7,680 KB
testcase_29 AC 13 ms
5,888 KB
testcase_30 AC 11 ms
5,632 KB
testcase_31 AC 17 ms
7,168 KB
testcase_32 AC 13 ms
6,016 KB
testcase_33 AC 41 ms
11,520 KB
testcase_34 AC 40 ms
11,520 KB
testcase_35 AC 40 ms
11,648 KB
testcase_36 AC 38 ms
11,520 KB
testcase_37 AC 37 ms
11,520 KB
testcase_38 AC 37 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
const long long mod = 1e9+7;
char s[100001];
long long f[100001][10];

int digitSum(int u){
    while(u>9){
        int v = 0;
        while(u){
            v += u%10;
            u /= 10;
        }
        u = v;
    }
    return u;
}

int main(){
    //for(int i = 1; i <= 20; i++) printf("i = %d: %d\n",i,digitSum(i));
    int d;
    scanf("%s%d",s+1,&d);
    int n = strlen(s+1);
    int sum = 0, cnt = 0;
    for(int i = 1; i <= n; i++){
        if(s[i]!='?') sum += s[i]-'0';
        else cnt++;
    }
    if(d==0){
        if(sum==0) printf("1\n");
        else printf("0\n");
    }
    else{
        int begin = (sum%9)-1;
        if(begin<0) begin += 9;
        f[0][begin] = 1;
        for(int i = 1; i <= cnt; i++){
            for(int j = 0; j <= 8; j++){
                f[i][j] = 0;
                for(int k = 0; k <= 9; k++){
                    int last = (j-k)%9;
                    if(last<0) last += 9;
                    f[i][j] = (f[i][j] + f[i-1][last])%mod;
                }
            }
        }
        if(d==9 && sum==0) f[cnt][d-1]--;
        if(f[cnt][d-1]<0) f[cnt][d-1] += mod;
        printf("%lld\n",f[cnt][d-1]);
    }
    
    return 0;
}
0