結果

問題 No.1085 桁和の桁和
ユーザー vwxyzvwxyz
提出日時 2021-08-12 01:05:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 6,439 ms
コンパイル使用メモリ 271,748 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 03:04:57
合計ジャッジ時間 7,452 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 22 ms
4,348 KB
testcase_15 AC 56 ms
4,348 KB
testcase_16 AC 49 ms
4,348 KB
testcase_17 AC 24 ms
4,348 KB
testcase_18 AC 14 ms
4,348 KB
testcase_19 AC 45 ms
4,348 KB
testcase_20 WA -
testcase_21 AC 29 ms
4,348 KB
testcase_22 AC 41 ms
4,348 KB
testcase_23 AC 6 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 26 ms
4,348 KB
testcase_26 AC 51 ms
4,348 KB
testcase_27 AC 42 ms
4,348 KB
testcase_28 AC 58 ms
4,348 KB
testcase_29 AC 31 ms
4,348 KB
testcase_30 AC 29 ms
4,348 KB
testcase_31 AC 49 ms
4,348 KB
testcase_32 AC 34 ms
4,348 KB
testcase_33 AC 87 ms
4,348 KB
testcase_34 AC 88 ms
4,348 KB
testcase_35 AC 88 ms
4,348 KB
testcase_36 AC 88 ms
4,348 KB
testcase_37 AC 88 ms
4,348 KB
testcase_38 AC 88 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main(){
    string S;
    cin>>S;
    int D;
    cin>>D;
    int ans;
    if(D==0){
        bool bl=false;
        for(char s:S){
            if(s!='0'&&s!='?'){
                ans=0;
                bl=true;
                break;
            }
        }
        if(bl){
            ans=1;
        }
    }
    else{
        D%=9;
        int mod=pow(10,9)+7;
        vector<int> dp(9,0);
        dp[0]=1;
        vector<int> prev(9,0);
        for(int i=S.size()-1;i>=0;i--){
            char s=S[i];
            for(int i=0;i<9;i++){
                prev[i]=dp[i];
                dp[i]=0;
            }
            for(int i=0;i<9;i++){
                for(int j=0;j<10;j++){
                    if(s=='?'||int(s-'0')==j){
                        dp[(i+j)%9]+=prev[i];
                        dp[(i+j)%9]%=mod;
                    }
                }
            }
        }
        ans=dp[D];
        if(D==0){
            bool bl=true;
            for(char s:S){
                if(s!='0'&&s!='?'){
                    bl=false;
                }
            }
            if(bl){
                ans-=1;
                ans%=mod;
            }
        }
    }
    cout<<ans<<endl;
}
0