結果

問題 No.372 It's automatic
ユーザー maspy
提出日時 2020-03-17 02:43:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,082 ms / 6,000 ms
コード長 547 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 249,984 KB
最終ジャッジ日時 2024-11-29 02:11:17
合計ジャッジ時間 26,645 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9 + 7

# %%
S = [int(x) - ord('0') for x in readline().rstrip()]
M = int(read())

# %%
dp = [0] * M
for x in S:
    newdp = [0] * M
    if x != 0:
        newdp[x % M] += 1
    for i in range(M):
        newdp[(10 * i + x) % M] += dp[i]
    for i in range(M):
        newdp[i] += dp[i]
        newdp[i] %= MOD
    dp = newdp

# %%
answer = sum(x == 0 for x in S) + dp[0]
print(answer % MOD)
0