結果

問題 No.372 It's automatic
ユーザー kenkooookenkoooo
提出日時 2016-05-14 03:20:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 5,912 ms / 6,000 ms
コード長 1,056 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 261,760 KB
最終ジャッジ日時 2024-04-15 20:43:37
合計ジャッジ時間 70,631 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
52,352 KB
testcase_01 AC 44 ms
52,096 KB
testcase_02 AC 46 ms
52,096 KB
testcase_03 AC 44 ms
51,968 KB
testcase_04 AC 5,540 ms
260,608 KB
testcase_05 AC 5,584 ms
260,864 KB
testcase_06 AC 5,514 ms
261,632 KB
testcase_07 AC 5,692 ms
260,736 KB
testcase_08 AC 5,643 ms
261,760 KB
testcase_09 AC 5,566 ms
261,248 KB
testcase_10 AC 5,490 ms
261,632 KB
testcase_11 AC 5,548 ms
261,760 KB
testcase_12 AC 5,756 ms
260,736 KB
testcase_13 AC 5,574 ms
261,504 KB
testcase_14 AC 5,556 ms
261,504 KB
testcase_15 AC 5,912 ms
260,736 KB
testcase_16 AC 50 ms
58,368 KB
testcase_17 AC 50 ms
58,496 KB
testcase_18 AC 50 ms
58,624 KB
testcase_19 AC 51 ms
58,368 KB
testcase_20 AC 51 ms
59,008 KB
testcase_21 AC 303 ms
76,160 KB
testcase_22 AC 322 ms
76,032 KB
testcase_23 AC 310 ms
76,032 KB
testcase_24 AC 313 ms
76,032 KB
testcase_25 AC 311 ms
76,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main(S, M):
    MOD = 10 ** 9 + 7

    remainder = []
    for i in range(0, M):
        remainder.append((
            (i * 10) % M,
            (i * 10 + 1) % M,
            (i * 10 + 2) % M,
            (i * 10 + 3) % M,
            (i * 10 + 4) % M,
            (i * 10 + 5) % M,
            (i * 10 + 6) % M,
            (i * 10 + 7) % M,
            (i * 10 + 8) % M,
            (i * 10 + 9) % M
        ))
    dp = [0] * M
    dp[0] = 1
    zeros = 0
    for s in S:
        nex = [0] * M
        si = int(s)
        for m in range(0, M):
            nex[m] += dp[m]
            if nex[m] >= MOD:
                nex[m] -= MOD

            r = remainder[m][si]
            nex[r] += dp[m]
            if m == 0 and si == 0:
                zeros += 1
                nex[r] -= 1
                if nex[r] < 0:
                    nex[r] += MOD
            if nex[r] >= MOD:
                nex[r] -= MOD
        dp = nex
    print((dp[0] + zeros - 1 + MOD) % MOD)


if __name__ == "__main__":
    S = input()
    M = int(input())
    main(S, M)
0