結果

問題 No.372 It's automatic
ユーザー りあんりあん
提出日時 2016-05-14 22:50:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,461 ms / 6,000 ms
コード長 884 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 164,896 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 08:21:53
合計ジャッジ時間 32,706 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2,446 ms
6,940 KB
testcase_05 AC 2,439 ms
6,940 KB
testcase_06 AC 2,431 ms
6,940 KB
testcase_07 AC 2,461 ms
6,944 KB
testcase_08 AC 2,438 ms
6,940 KB
testcase_09 AC 2,428 ms
6,940 KB
testcase_10 AC 2,429 ms
6,944 KB
testcase_11 AC 2,422 ms
6,944 KB
testcase_12 AC 2,454 ms
6,940 KB
testcase_13 AC 2,427 ms
6,944 KB
testcase_14 AC 2,443 ms
6,940 KB
testcase_15 AC 2,448 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 116 ms
6,944 KB
testcase_22 AC 119 ms
6,940 KB
testcase_23 AC 117 ms
6,940 KB
testcase_24 AC 120 ms
6,940 KB
testcase_25 AC 120 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long dp[2][20001];
int nex[20001][10];
int M = 1000000007;
int main(){
    string s;
    cin >> s;
    int n = s.length(), m;
    cin >> m;
    int zero = -1;
    dp[0][0] = 1;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < 10; ++j) {
            nex[i][j] = (i * 10 + j) % m;
        }
    }
    for (int i = 0, ii = 0; i < n; ++i, ii ^= 1)
    {
        int t = s[i] - '0';
        int ij = ii ^ 1;
        for (int j = 0; j < m; j++)
        {
            dp[ij][j] += dp[ii][j];
            dp[ij][nex[j][t]] += dp[ii][j];
        }
        if (!t)
        {
            dp[ij][0] = (dp[ij][0] + M - 1) % M;
            ++zero;
        }
        for (int j = 0; j < m; ++j) {
            dp[ij][j] %= M;
            dp[ii][j] = 0;
        }
    }
    cout << (dp[n & 1][0] + zero + M) % M << "\n";
    return 0;
}
0