結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー brthyyjpbrthyyjp
提出日時 2021-03-05 23:11:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 654 ms / 3,000 ms
コード長 2,120 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 183,680 KB
最終ジャッジ日時 2024-04-16 11:09:26
合計ジャッジ時間 8,324 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
95,164 KB
testcase_01 AC 95 ms
95,016 KB
testcase_02 AC 102 ms
95,904 KB
testcase_03 AC 84 ms
94,976 KB
testcase_04 AC 93 ms
95,232 KB
testcase_05 AC 93 ms
95,104 KB
testcase_06 AC 94 ms
95,360 KB
testcase_07 AC 91 ms
94,848 KB
testcase_08 AC 97 ms
95,232 KB
testcase_09 AC 100 ms
95,060 KB
testcase_10 AC 95 ms
94,976 KB
testcase_11 AC 95 ms
95,108 KB
testcase_12 AC 97 ms
95,224 KB
testcase_13 AC 100 ms
95,140 KB
testcase_14 AC 98 ms
95,232 KB
testcase_15 AC 110 ms
95,536 KB
testcase_16 AC 104 ms
95,744 KB
testcase_17 AC 105 ms
95,516 KB
testcase_18 AC 106 ms
95,616 KB
testcase_19 AC 107 ms
95,732 KB
testcase_20 AC 102 ms
96,000 KB
testcase_21 AC 107 ms
95,844 KB
testcase_22 AC 110 ms
95,928 KB
testcase_23 AC 107 ms
95,952 KB
testcase_24 AC 101 ms
96,048 KB
testcase_25 AC 105 ms
96,508 KB
testcase_26 AC 106 ms
96,152 KB
testcase_27 AC 103 ms
96,056 KB
testcase_28 AC 106 ms
95,892 KB
testcase_29 AC 104 ms
96,128 KB
testcase_30 AC 148 ms
102,272 KB
testcase_31 AC 148 ms
103,992 KB
testcase_32 AC 225 ms
113,100 KB
testcase_33 AC 367 ms
139,864 KB
testcase_34 AC 620 ms
182,144 KB
testcase_35 AC 633 ms
183,680 KB
testcase_36 AC 636 ms
183,680 KB
testcase_37 AC 654 ms
183,168 KB
testcase_38 AC 550 ms
183,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = str(input())

n = len(s)
#print(n)
mod = 10**9+7

dp = [[[0, 0] for _ in range(100)] for _ in range(n+1)]
dp[0][0][0] = 1

for i in range(n):
    for j in range(100):
        for k in range(2):
            nd = int(s[i])
            for d in range(10):
                ni = i+1
                if i == 0:
                    nj = d%100
                else:
                    nj = (j*d)%100
                nk = k
                if k == 0:
                    if d > nd:
                        continue
                    elif d < nd:
                        nk = 1
                    else:
                        pass
                if d != 0:
                    dp[ni][nj][nk] += dp[i][j][k]%mod
#print(dp)
#print((dp[n][0][0]+dp[n][0][1])%mod)
ans = (dp[n][0][0]+dp[n][0][1])%mod

N = 10**6
mod = 10**9+7
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
    fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(range(N)):
    finv[i] = finv[i+1] * (i+1) % mod

def cmb1(n, r, mod):
    if r <0 or r > n:
        return 0
    r = min(r, n-r)
    return fac[n] * finv[r] * finv[n-r] % mod

def prm1(n, r, mod):
    if r <0 or r > n:
        return 0
    return fac[n] * finv[n-r] % mod

table9 = [0]*(10**5+50)
table9[0] = 1
for i in range(1, 10**5+50):
    table9[i] = table9[i-1]*9
    table9[i] %= mod

table4 = [0]*(10**5+50)
table4[0] = 1
for i in range(1, 10**5+50):
    table4[i] = table4[i-1]*4
    table4[i] %= mod

table5 = [0]*(10**5+50)
table5[0] = 1
for i in range(1, 10**5+50):
    table5[i] = table5[i-1]*5
    table5[i] %= mod

table8 = [0]*(10**5+50)
table8[0] = 1
for i in range(1, 10**5+50):
    table8[i] = table8[i-1]*8
    table8[i] %= mod

for i in range(n):
    if i < 3:
        continue
    temp = table9[i]
    # 5:0, 2, 6:0
    temp -= table4[i]
    # 5:0, 2, 6:1
    temp -= i*2*table4[i-1]
    # 5:1, 2, 6:0
    temp -= i*1*table4[i-1]
    # 5:1, 2, 6:1
    temp -= cmb1(i, 2, mod)*2*2*table4[i-2]
    #print(i, temp)
    a = table9[i]-table8[i]-i*table8[i-1]
    b = table9[i]-table5[i]-i*2*table5[i-1]
    ans += a+b-temp

print(ans%mod)
0