結果

問題 No.3549 SigMax Digits (Judge ver.)
コンテスト
ユーザー K2
提出日時 2026-05-22 23:59:48
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 691 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 600 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 15,484 KB
最終ジャッジ日時 2026-05-23 00:00:09
合計ジャッジ時間 5,565 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 桁dp...めんどい~~
# dp[i][x][f] = (上からi桁決めて、未満フラグがfで、現在の最大値がxな個数)
# TLE???


def calc(n: int):
    dp = [[0] * 2 for _ in range(10)]
    dp[0][0] = 1
    for s in str(n):
        s = int(s)
        ndp = [[0] * 2 for _ in range(10)]
        for j in range(10):
            for x in range(10):
                ndp[max(j, x)][1] += dp[j][1]
                if x <= s:
                    ndp[max(j, x)][x < s] += dp[j][0]
        dp = ndp
    return sum(sum(dp[i]) * i for i in range(10))


def solve():
    l, r = map(int, input().split())
    print(calc(r) - calc(l - 1))


T = int(input())
for _ in range(T):
    solve()
0