結果

問題 No.372 It's automatic
ユーザー りあんりあん
提出日時 2016-05-14 00:46:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 894 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 164,380 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 08:10:56
合計ジャッジ時間 55,051 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 4,280 ms
6,944 KB
testcase_05 AC 4,293 ms
6,940 KB
testcase_06 AC 4,282 ms
6,940 KB
testcase_07 AC 4,300 ms
6,940 KB
testcase_08 AC 4,314 ms
6,944 KB
testcase_09 AC 4,292 ms
6,940 KB
testcase_10 AC 4,303 ms
6,940 KB
testcase_11 AC 4,259 ms
6,940 KB
testcase_12 AC 4,312 ms
6,940 KB
testcase_13 AC 4,267 ms
6,940 KB
testcase_14 AC 4,302 ms
6,940 KB
testcase_15 AC 4,316 ms
6,940 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,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 215 ms
6,944 KB
testcase_22 AC 216 ms
6,940 KB
testcase_23 AC 214 ms
6,940 KB
testcase_24 AC 215 ms
6,940 KB
testcase_25 AC 215 ms
6,944 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)
    {
        for (int j = 0; j < m; j++)
        {
            dp[ii ^ 1][j] = (dp[ii ^ 1][j] + dp[ii][j]) % M;
            k = nex[j][s[i] - '0'];
            dp[ii ^ 1][k] = (dp[ii ^ 1][k] + dp[ii][j]) % M;
            
            dp[ii][j] = 0;
        }
        if (s[i] == '0')
        {
            if (dp[ii ^ 1][0]) --dp[ii ^ 1][0];
            else dp[ii ^ 1][0] = M - 1;

            ++zero;
        }
    }
    cout << (dp[n & 1][0] + zero) % M << "\n";
    return 0;
}
0