結果

問題 No.3549 SigMax Digits (Judge ver.)
コンテスト
ユーザー 回転
提出日時 2026-05-22 22:59:53
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 885 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 71 ms
コンパイル使用メモリ 80,624 KB
実行使用メモリ 137,300 KB
最終ジャッジ日時 2026-10-01 17:00:30
合計ジャッジ時間 12,384 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other TLE * 2 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from functools import cache
T = int(input())

for _ in range(T):
    L,R = input().split()
    L = str(int(L)-1)
    L_keta,R_keta = len(L), len(R)

    @cache
    def f(n, MAX, giri):
        if(n == R_keta):return MAX
        ret = 0
        if(giri):
            for i in range(int(R[n])+1):
                ret += f(n+1, max(MAX, i), int(R[n]) == i)
            return ret
        else:
            for i in range(10):
                ret += f(n+1, max(MAX, i), False)
            return ret
    
    @cache
    def g(n, MAX, giri):
        if(n == L_keta):return MAX
        ret = 0
        if(giri):
            for i in range(int(L[n])+1):
                ret += g(n+1, max(MAX, i), int(L[n]) == i)
            return ret
        else:
            for i in range(10):
                ret += g(n+1, max(MAX, i), False)
            return ret

    print(f(0,0,True) - g(0,0,True))
0