結果

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

ソースコード

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