結果

問題 No.372 It's automatic
ユーザー arrowsarrows
提出日時 2016-05-14 00:27:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 160,980 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 17:59:38
合計ジャッジ時間 17,551 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define MAX_M 20001
#define MOD 1000000007
typedef long long ll;

int c2i(char c)
{
    return c - '0';
}

ll dp[2][MAX_M], res = 0;

int main()
{
    string S;
    int M;
    cin >> S >> M;

    memset(dp, 0, sizeof(dp));
    dp[0][c2i(S[0]) % M] = 1;
    res = dp[0][0];
    if (c2i(S[0]) == 0) dp[0][c2i(S[0])] = 0;
    for (int i = 1; i < (int)S.size(); i++) {
        int si = !(i & 1), ti = !si;
        int num = c2i(S[i]);
        int n = num;
        num %= M;
        if (num > 0 && n != 0) dp[si][num]++;
        for (int j = 0; j < M; j++) {
            dp[ti][(10*j + num) % M] += dp[si][j];
            dp[ti][(10*j + num) % M] %= MOD;
            dp[ti][j] += dp[si][j];
            dp[ti][j] %= MOD;
        }
        res += dp[ti][0];
        fill(dp[si], dp[si] + M, 0);
        res %= MOD;
    }
    cout << res%MOD << endl;
    return 0;
}
0