結果

問題 No.3242 Count 8 Included Numbers (Hard)
ユーザー titia
提出日時 2025-08-23 01:27:59
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,031 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,680 KB
実行使用メモリ 848,884 KB
最終ジャッジ日時 2025-08-23 01:28:05
合計ジャッジ時間 5,007 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 1 MLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

sys.setrecursionlimit(10**7)
sys.set_int_max_str_digits(10**7)

mod=998244353

N=input().strip()

from functools import lru_cache
@lru_cache(maxsize=None)
def calc(keta,minus):
    if keta==0:
        x=int(N[0])-minus
        if x<8:
            return 0
        if x==8 or x==9:
            return 1

    x=int(N[keta])-minus

    if x-8<0:
        ANS=calc2(keta-1,1)
    else:
        ANS=calc2(keta-1,0)

    for i in [0,1,2,3,4,5,6,7,9]:
        if x-i<0:
            ANS+=calc(keta-1,1)
        else:
            ANS+=calc(keta-1,0)
            
        ANS%=mod

    return ANS

@lru_cache(maxsize=None)
def calc2(keta,minus):
    if keta==0:
        x=int(N[keta])-minus
        return x+1
    if keta==1:
        x=int(N[:keta+1])-minus
        return x+1

    x=int(N[keta])-minus
    ANS=0

    for i in range(10):
        if x-i<0:
            ANS+=calc2(keta-1,1)
        else:
            ANS+=calc2(keta-1,0)

    return ANS
            
        

print(calc(len(N)-1,0)%mod)
0