結果

問題 No.260 世界のなんとか3
ユーザー asumo0729asumo0729
提出日時 2022-02-12 17:05:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 2,971 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 11,272 KB
実行使用メモリ 19,480 KB
最終ジャッジ日時 2023-09-11 04:47:51
合計ジャッジ時間 5,479 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
9,148 KB
testcase_01 AC 23 ms
9,092 KB
testcase_02 AC 23 ms
9,228 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 622 ms
18,164 KB
testcase_06 AC 416 ms
14,612 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 844 ms
19,480 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 399 ms
12,240 KB
testcase_14 RE -
testcase_15 AC 556 ms
13,632 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 204 ms
10,788 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 22 ms
9,100 KB
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

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