結果

問題 No.1085 桁和の桁和
ユーザー DriceDrice
提出日時 2020-06-20 20:32:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,126 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 32,888 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2023-09-30 06:30:24
合計ジャッジ時間 2,232 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 9 ms
4,488 KB
testcase_15 AC 19 ms
7,180 KB
testcase_16 AC 19 ms
7,160 KB
testcase_17 AC 10 ms
4,556 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 17 ms
7,132 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 12 ms
4,876 KB
testcase_22 AC 16 ms
7,176 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 10 ms
4,708 KB
testcase_26 AC 19 ms
7,132 KB
testcase_27 AC 16 ms
7,144 KB
testcase_28 AC 21 ms
7,228 KB
testcase_29 AC 13 ms
7,188 KB
testcase_30 AC 12 ms
4,884 KB
testcase_31 AC 18 ms
7,224 KB
testcase_32 AC 14 ms
7,104 KB
testcase_33 AC 39 ms
10,840 KB
testcase_34 AC 39 ms
10,880 KB
testcase_35 AC 39 ms
10,752 KB
testcase_36 AC 39 ms
10,844 KB
testcase_37 AC 39 ms
10,852 KB
testcase_38 AC 39 ms
10,816 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;
                }
            }
        }
        printf("%lld\n",f[cnt][d-1]);
    }
    
    return 0;
}
0