結果

問題 No.372 It's automatic
ユーザー roarisroaris
提出日時 2019-12-12 15:40:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 896 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 165,732 KB
実行使用メモリ 812,692 KB
最終ジャッジ日時 2023-09-07 07:50:04
合計ジャッジ時間 3,915 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007

signed main() {
    string S; cin >> S;
    int M; cin >> M;
    int dp[S.size()+1][M];
    
    for (int i=0; i<=S.size(); i++) {
        for (int j=0; j<M; j++) {
            dp[i][j] = 0;
        }
    }
    
    for (int i=0; i<S.size(); i++) {
        for (int j=0; j<M; j++) {
            dp[i+1][j] = dp[i][j];
        }
        
        int n = S[i]-'0';
        
        if (n!=0) {
            dp[i+1][n%M] += 1;
            dp[i+1][n%M] %= MOD;
        }
        
        for (int j=0; j<M; j++) {
            dp[i+1][(10*j+n)%M] += dp[i][j];
            dp[i+1][(10*j+n)%M] %= MOD;
        }
    }
    
    int ans = dp[S.size()][0];
    
    for (int i=0; i<=S.size(); i++) {
        if (S[i]=='0') {
            ans++;
            ans %= MOD;
        }
    }
    
    cout << ans << endl;
}
0