結果
| 問題 | No.260 世界のなんとか3 |
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2021-02-19 09:13:47 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 983 bytes |
| 記録 | |
| コンパイル時間 | 85 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 27,520 KB |
| 最終ジャッジ日時 | 2024-09-15 13:30:38 |
| 合計ジャッジ時間 | 9,048 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 RE * 20 |
ソースコード
from itertools import product
A,B = map(int,input().split())
A = str(A-1)
B = str(B)
mod=10**9+7
def count(a):
n = len(a)
dp=[[[[[0] * 8 for i in range(2)] for j in range(3)] for k in range(2)] for l in range(n+1)]
dp[0][0][0][0][0] = 1
for i, less, mod3, has3, mod8 in product(range(n), (0,1), range(3), (0,1), range(8)):
max_d = 9 if less else int(a[i])
for d in range(max_d+1):
less_ = less or d < max_d
mod3_ = (mod3*10+d)%3
has3_ = has3 or d==3
mod8_ = (mod8*10+d)%8
dp[i + 1][less_][mod3_][has3_][mod8_] = (dp[i + 1][less_][mod3_][has3_][mod8_]+dp[i][less][mod3][has3][mod8])%mod
cnt = 0
for less,mod8 in product((0,1),range(1,8)):
cnt = (cnt+dp[n][less][0][1][mod8])%mod
cnt = (cnt+dp[n][less][1][1][mod8])%mod
cnt = (cnt+dp[n][less][2][1][mod8])%mod
cnt = (cnt+dp[n][less][0][0][mod8])%mod
return cnt
print((count(B)-count(A))%mod)
H20