結果

問題 No.1085 桁和の桁和
ユーザー chocoruskchocorusk
提出日時 2020-06-19 22:09:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,549 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 127,784 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2023-08-06 14:29:18
合計ジャッジ時間 3,108 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,164 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 4 ms
11,164 KB
testcase_03 AC 4 ms
11,296 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 4 ms
11,168 KB
testcase_08 AC 4 ms
11,220 KB
testcase_09 AC 5 ms
11,292 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
11,172 KB
testcase_12 AC 4 ms
11,224 KB
testcase_13 AC 7 ms
11,256 KB
testcase_14 AC 10 ms
11,520 KB
testcase_15 AC 18 ms
11,360 KB
testcase_16 AC 18 ms
11,360 KB
testcase_17 AC 11 ms
11,268 KB
testcase_18 AC 8 ms
11,276 KB
testcase_19 AC 17 ms
11,304 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 12 ms
11,260 KB
testcase_22 AC 16 ms
11,464 KB
testcase_23 AC 6 ms
11,188 KB
testcase_24 AC 5 ms
11,264 KB
testcase_25 AC 12 ms
11,336 KB
testcase_26 AC 19 ms
11,352 KB
testcase_27 AC 17 ms
11,356 KB
testcase_28 AC 20 ms
11,360 KB
testcase_29 AC 13 ms
11,336 KB
testcase_30 AC 12 ms
11,324 KB
testcase_31 AC 18 ms
11,296 KB
testcase_32 AC 14 ms
11,284 KB
testcase_33 AC 30 ms
11,288 KB
testcase_34 AC 30 ms
11,360 KB
testcase_35 AC 30 ms
11,356 KB
testcase_36 AC 30 ms
11,356 KB
testcase_37 AC 30 ms
11,288 KB
testcase_38 AC 30 ms
11,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
    string s; cin>>s;
    int n=s.size();
    int d; cin>>d;
    if(d==0){
        for(int i=0; i<n; i++){
            if(s[i]!='0' && s[i]!='?'){
                cout<<0<<endl;
                return 0;
            }
        }
        cout<<1<<endl;
        return 0;
    }
    ll dp[10][100010]={};
    dp[0][0]=1;
  ll c[9];
  for(int i=0; i<10; i++) c[i%9]++;
    for(int i=0; i<n; i++){
        if(s[i]!='?'){
            int x=s[i]-'0';
            for(int j=0; j<9; j++){
                (dp[(x+j)%9][i+1]+=dp[j][i])%=MOD;
            }
        }else{
            for(int x=0; x<9; x++){
                for(int j=0; j<9; j++){
                    (dp[(x+j)%9][i+1]+=c[x]*dp[j][i])%=MOD;
                }
            }
        }
    }
    if(d==9){
        bool myon=1;
        for(int i=0; i<n; i++){
            if(s[i]!='?' && s[i]!='0') myon=0;
        }
        if(myon) (dp[d%9][n]+=MOD-1)%=MOD;
    }
    cout<<dp[d%9][n]<<endl;
    return 0;
}
0