結果

問題 No.260 世界のなんとか3
ユーザー 👑 rin204rin204
提出日時 2022-10-28 19:41:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,601 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 13,120 KB
最終ジャッジ日時 2023-09-20 02:35:54
合計ジャッジ時間 4,130 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

MOD = 10 ** 9 + 7

def solve(S):
    if not S:
        return 0
    dp = [[0] * 2 for _ in range(24)]

    for s in range(1, S[0]):
        if s == 3:
            dp[s][1] = 1
        else:
            dp[s][0] = 1
    
    eqi = S[0]
    if S[0] == 3:
        eqj = 1
    else:
        eqj = 0

    for s in S[1:]:
        ndp = [[0] * 2 for _ in range(24)]
        for x in range(10):
            for i in range(24):
                ni = (i * 10 + x) % 24
                for j in range(2):
                    if x == 3:
                        nj = 1
                    else:
                        nj = j

                    ndp[ni][nj] += dp[i][j]
                    ndp[ni][nj] %= MOD

        for i in range(1, 10):
            if i == 3:
                ndp[i][1] += 1
            else:
                ndp[i][0] += 1

        for i in range(s):
            ni = (eqi * 10 + i) % 24
            if i == 3:
                nj = 1
            else:
                nj = eqj
            ndp[ni][nj] += 1

        eqi *= 10
        eqi += s
        eqi %= 24
        if s == 3:
            eqj = 1
        dp = ndp

    
    dp[eqi][eqj] += 1
    

    ret = 0
    for i in range(24):
        if i % 8 == 0:
            continue
        ret += dp[i][1]
        if i % 3 == 0:
            ret += dp[i][0]
        ret %= MOD

    return ret

    

A, B = input().split()
A = list(map(int, A))
B = list(map(int, B))
i = len(A) - 1
while 1:
    A[i] -= 1
    if A[i] == -1:
        A[i] = 9
        i -= 1
    else:
        break

if A[0] == 0:
    A = A[1:]

ans = solve(B) - solve(A)
print(ans)
0