結果

問題 No.260 世界のなんとか3
ユーザー asumo0729asumo0729
提出日時 2022-02-12 17:04:45
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,971 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 85,400 KB
最終ジャッジ日時 2023-09-11 04:47:10
合計ジャッジ時間 8,191 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
testcase_29 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from operator import itemgetter
from collections import defaultdict, deque
import heapq
import bisect
import math
import itertools

stdin=sys.stdin
sys.setrecursionlimit(10 ** 8)

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()
Yp=lambda:print('Yes')
Np=lambda:print('No')
inf = 1 << 60
inf1 = float('inf')
mod = 10 ** 9 + 7
#mod = 998244353
eps = 1e-9
sortkey1 = itemgetter(0)
sortkey2 = lambda x: (x[0], x[1])

###############################################################
A, B = lp()
A -= 1

def f(x):
    y = str(x)
    L = len(y)
    dp = [[ 0 for _ in range(2)] for _ in range(L + 1)]
    dp3 = [[[0 for _ in range(3)] for _ in range(2)] for _ in range(L + 1)]
    dp8 = [[[0 for _ in range(8)] for _ in range(2)] for _ in range(L + 1)]
    dp24 = [[[0 for _ in range(24)] for _ in range(2)] for _ in range(L + 1)]
    dp[0][1] = 1
    dp3[0][1][0] = 1
    dp8[0][1][0] = 1
    dp24[0][1][0] = 1
    ## xより小さいことが 0 => 確定している 1 => していない
    for i in range(L):
        now = int(y[i])
        for dig in range(10):
            if dig == 3:
                continue
            dp[i + 1][0] = (dp[i + 1][0] + dp[i][0]) % mod
            for j in range(3):
                dp3[i + 1][0][(j + dig) % 3] = (dp3[i + 1][0][(j + dig) % 3] + dp3[i][0][j]) % mod
            for j in range(8):
                dp8[i + 1][0][(j * 10 + dig) % 8] = (dp8[i + 1][0][(j * 10 + dig) % 8] + dp8[i][0][j]) % mod
            for j in range(24):
                dp24[i + 1][0][(j * 10 + dig) % 24] = (dp24[i + 1][0][(j * 10 + dig) % 24] + dp24[i][0][j]) % mod
        for dig in range(now):
            if dig == 3:
                continue
            dp[i + 1][0] = (dp[i + 1][0] + dp[i][1]) % mod
            for j in range(3):
                dp3[i + 1][0][(j + dig) % 3] = (dp3[i + 1][0][(j + dig) % 3] + dp3[i][1][j]) % mod
            for j in range(8):
                dp8[i + 1][0][(j * 10 + dig) % 8] = (dp8[i + 1][0][(j * 10 + dig) % 8] + dp8[i][1][j]) % mod
            for j in range(24):
                dp24[i + 1][0][(j * 10 + dig) % 24] = (dp24[i + 1][0][(j * 10 + dig) % 24] + dp24[i][1][j]) % mod

        if now ==3:
            continue
        dp[i + 1][1] = (dp[i + 1][1] + dp[i][1]) % mod
        for j in range(3):
            dp3[i + 1][1][(j + now) % 3] = (dp3[i + 1][1][(j + now) % 3] + dp3[i][1][j]) % mod
        for j in range(8):
            dp8[i + 1][1][(j * 10 + now) % 8] = (dp8[i + 1][1][(j * 10 + now) % 8] + dp8[i][1][j]) % mod
        for j in range(24):
            dp24[i + 1][1][(j * 10 + now) % 24] = (dp24[i + 1][1][(j * 10 + now) % 24] + dp24[i][1][j]) % mod
        
    res = x - (dp[L][0] + dp[L][1])
    res += dp3[L][0][0] + dp3[L][1][0]
    res -= x // 8 - (dp8[L][0][0] + dp8[L][1][0])
    res -= dp24[L][0][0] + dp24[L][1][0]
    res %= mod
    return res

ans = f(B) - f(A)
ans %= mod
print(ans)
0