結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー nephrologistnephrologist
提出日時 2021-03-05 21:59:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 206 ms / 3,000 ms
コード長 1,751 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 88,416 KB
最終ジャッジ日時 2024-04-16 09:28:25
合計ジャッジ時間 4,663 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,096 KB
testcase_01 AC 36 ms
52,960 KB
testcase_02 AC 65 ms
71,680 KB
testcase_03 AC 36 ms
52,096 KB
testcase_04 AC 37 ms
52,096 KB
testcase_05 AC 37 ms
52,224 KB
testcase_06 AC 36 ms
52,352 KB
testcase_07 AC 37 ms
52,480 KB
testcase_08 AC 38 ms
52,648 KB
testcase_09 AC 36 ms
52,992 KB
testcase_10 AC 36 ms
52,480 KB
testcase_11 AC 38 ms
52,480 KB
testcase_12 AC 46 ms
61,312 KB
testcase_13 AC 46 ms
61,312 KB
testcase_14 AC 48 ms
62,336 KB
testcase_15 AC 56 ms
65,408 KB
testcase_16 AC 66 ms
70,656 KB
testcase_17 AC 68 ms
71,808 KB
testcase_18 AC 82 ms
76,288 KB
testcase_19 AC 83 ms
76,672 KB
testcase_20 AC 89 ms
76,608 KB
testcase_21 AC 84 ms
76,644 KB
testcase_22 AC 89 ms
76,716 KB
testcase_23 AC 87 ms
76,544 KB
testcase_24 AC 68 ms
72,320 KB
testcase_25 AC 92 ms
76,328 KB
testcase_26 AC 88 ms
76,288 KB
testcase_27 AC 90 ms
76,416 KB
testcase_28 AC 89 ms
76,544 KB
testcase_29 AC 98 ms
76,680 KB
testcase_30 AC 118 ms
78,040 KB
testcase_31 AC 93 ms
78,172 KB
testcase_32 AC 164 ms
80,088 KB
testcase_33 AC 145 ms
82,456 KB
testcase_34 AC 203 ms
88,004 KB
testcase_35 AC 201 ms
88,376 KB
testcase_36 AC 204 ms
88,416 KB
testcase_37 AC 206 ms
87,772 KB
testcase_38 AC 150 ms
87,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()

keta = len(s)

dp = [[[[0] * (2) for _ in range(3)] for _ in range(3)] for _ in range(keta + 1)]

# dp[keta][*2][*5][smaller]
mod = 10 ** 9 + 7
dp[0][0][0][0] = 1
for i in range(1, keta):
    dp[i][0][0][1] = 1
for i in range(keta):
    ni = i + 1
    num = int(s[i])
    for j in range(3):
        for k in range(3):
            for smaller in range(2):
                if smaller:
                    for d in range(10):
                        if d == 0:
                            continue
                        nj = j
                        nk = k
                        nsmaller = smaller
                        if d == 4 or d == 8:
                            nj = 2
                        elif d % 2 == 0:
                            nj = min(2, j + 1)
                        if d == 5:
                            nk = min(2, k + 1)
                        dp[ni][nj][nk][nsmaller] += dp[i][j][k][smaller]
                        dp[ni][nj][nk][nsmaller] %= mod
                else:
                    for d in range(num + 1):
                        nj = j
                        nk = k
                        nsmaller = 1
                        if d == num:
                            nsmaller = 0
                        if d == 0:
                            continue

                        if d == 4 or d == 8:
                            nj = 2
                        elif d % 2 == 0:
                            nj = min(2, j + 1)
                        if d == 5:
                            nk = min(2, k + 1)
                        dp[ni][nj][nk][nsmaller] += dp[i][j][k][smaller]
                        dp[ni][nj][nk][nsmaller] %= mod

ans = dp[keta][2][2][0] + dp[keta][2][2][1]
print(ans % mod)

0