結果

問題 No.372 It's automatic
ユーザー kenkooookenkoooo
提出日時 2016-05-14 02:56:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 5,624 ms / 6,000 ms
コード長 834 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 259,072 KB
最終ジャッジ日時 2024-04-15 19:24:25
合計ジャッジ時間 68,468 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,196 KB
testcase_01 AC 42 ms
51,712 KB
testcase_02 AC 47 ms
51,968 KB
testcase_03 AC 45 ms
51,968 KB
testcase_04 AC 5,439 ms
258,560 KB
testcase_05 AC 5,455 ms
258,816 KB
testcase_06 AC 5,195 ms
258,904 KB
testcase_07 AC 5,624 ms
258,816 KB
testcase_08 AC 5,358 ms
259,072 KB
testcase_09 AC 5,551 ms
258,304 KB
testcase_10 AC 5,268 ms
258,688 KB
testcase_11 AC 5,305 ms
258,688 KB
testcase_12 AC 5,520 ms
258,816 KB
testcase_13 AC 5,228 ms
258,560 KB
testcase_14 AC 5,320 ms
259,072 KB
testcase_15 AC 5,539 ms
258,688 KB
testcase_16 AC 50 ms
60,800 KB
testcase_17 AC 49 ms
60,672 KB
testcase_18 AC 50 ms
60,676 KB
testcase_19 AC 53 ms
60,288 KB
testcase_20 AC 51 ms
60,544 KB
testcase_21 AC 288 ms
76,288 KB
testcase_22 AC 302 ms
75,904 KB
testcase_23 AC 283 ms
76,288 KB
testcase_24 AC 291 ms
76,544 KB
testcase_25 AC 303 ms
76,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    remainder = []
    for i in range(0, M):
        tmp = []
        for j in range(0, 10):
            tmp.append((i * 10 + j) % M)
        remainder.append(tmp)
    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__":
    main()
0