結果
問題 | No.1417 100の倍数かつ正整数(2) |
ユーザー |
![]() |
提出日時 | 2021-02-26 20:04:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 984 ms / 3,000 ms |
コード長 | 1,023 bytes |
コンパイル時間 | 721 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 128,020 KB |
最終ジャッジ日時 | 2024-10-02 12:25:42 |
合計ジャッジ時間 | 13,601 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
from itertools import productN = input()mod=10**9+7def count(a):n = len(a)dp=[[[[[0] * 2 for i in range(3)] for j in range(3)] for k in range(2)] for l in range(n+1)]dp[0][0][0][0][0] = 1for i, less, divcnt5, divcnt2, has0 in product(range(n), (0,1), range(3), range(3), (0,1)):max_d = 9 if less else int(a[i])for d in range(max_d+1):less_ = less or d < max_ddivcnt5_ = min(2,divcnt5+(d==5))if d==4 or d==8:divcnt2_=2elif d==2 or d==6:divcnt2_=min(2,divcnt2+1)else:divcnt2_ = divcnt2has0_ = has0 or d==0dp[i + 1][less_][divcnt5_][divcnt2_][has0_] = (dp[i + 1][less_][divcnt5_][divcnt2_][has0_] + dp[i][less][divcnt5][divcnt2][has0])%modreturn dpdp = count(N)ans = (dp[-1][0][2][2][0]+dp[-1][1][2][2][0])%moddp = count('9'*(len(N)-1))for i in range(len(N)):ans = (ans + dp[i][0][2][2][0]+dp[i][1][2][2][0])%modprint(ans)