結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー chineristAC
提出日時 2021-03-05 22:12:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 144 ms / 3,000 ms
コード長 1,812 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 77,952 KB
最終ジャッジ日時 2024-10-07 02:18:25
合計ジャッジ時間 5,463 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

def cmb(n, r, mod):#コンビネーションの高速計算 
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] % mod) * g2[n-r] % mod

mod = 998244353#出力の制限
N = 2*10**3
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inverse = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N = input()
n = len(N)
mod = 10**9 + 7

r = [1,2,4,5,10,20,25,50,100]
cond = {r:i for i,r in enumerate(r)}
def conv(i):
    cnt_2,cnt_5 = 0,0
    while i and i%2==0:
        cnt_2 += 1
        i //= 2
    while i and i%5==0:
        cnt_5 += 1
        i //= 5
    cnt_2,cnt_5 = min(cnt_2,2),min(cnt_5,2)
    return cond[2**cnt_2 * 5**cnt_5]

aaa = [conv(i) for i in range(10001)]

dp = [0 for i in range(18)]
for i in range(1,10):
    c = aaa[i]
    dp[c+9] += 1
    if i<=int(N[-1]):
        dp[c] += 1

res = 0
for i in range(1,n):
    s = int(N[-i-1])
    ndp = [0 for i in range(18)]
    for j in range(9):
        a = r[j]
        for k in range(1,10):
            next = aaa[a*k]
            if s>k:
                ndp[next] += dp[j+9]
            elif s==k:
                ndp[next] += dp[j]
            ndp[next] %= mod

            ndp[next+9] += dp[j+9]
            ndp[next+9] %= mod

    dp = ndp
    if i!=n-1:
        res += dp[17]
    else:
        res += dp[8]
    res %= mod

print(res)
0