結果

問題 No.372 It's automatic
ユーザー りあんりあん
提出日時 2016-05-14 01:20:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 857 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 163,580 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 08:09:48
合計ジャッジ時間 31,212 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2,332 ms
5,376 KB
testcase_05 AC 2,352 ms
5,376 KB
testcase_06 AC 2,389 ms
5,376 KB
testcase_07 AC 2,358 ms
5,376 KB
testcase_08 AC 2,364 ms
5,376 KB
testcase_09 AC 2,340 ms
5,376 KB
testcase_10 AC 2,347 ms
5,376 KB
testcase_11 AC 2,282 ms
5,376 KB
testcase_12 AC 2,419 ms
5,376 KB
testcase_13 AC 2,286 ms
5,376 KB
testcase_14 AC 2,306 ms
5,376 KB
testcase_15 AC 2,313 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 107 ms
5,376 KB
testcase_22 AC 109 ms
5,376 KB
testcase_23 AC 109 ms
5,376 KB
testcase_24 AC 109 ms
5,376 KB
testcase_25 AC 111 ms
5,376 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, k;
    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';
        for (int j = 0; j < m; j++)
        {
            dp[ii ^ 1][j] += dp[ii][j];
            dp[ii ^ 1][nex[j][t]] += dp[ii][j];
        }
        if (!t)
        {
            dp[ii ^ 1][0] += M - 1;
            ++zero;
        }
        for (int j = 0; j < m; ++j) {
            dp[ii ^ 1][j] %= M;
            dp[ii][j] = 0;
        }
    }
    cout << (dp[n & 1][0] + zero) % M << "\n";
    return 0;
}
0