結果

問題 No.8133 ‮Reversed‪
コンテスト
ユーザー K2
提出日時 2026-04-01 22:30:35
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 824 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 367 ms
コンパイル使用メモリ 20,956 KB
実行使用メモリ 58,988 KB
最終ジャッジ日時 2026-04-01 22:30:50
合計ジャッジ時間 4,061 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from functools import cache

def rev(n: int):
    return int(str(n)[::-1])


@cache
def solve(n: int):
    assert n >= 0
    if n < 1000:
        res = 0
        for i in range(1, n + 1):
            res += rev(i)
        return res

    s = str(n)
    L = len(s)
    res = 45

    for i in range(2, L):
        x = 10 ** (i - 1) - 1
        y = 10 ** (i - 2) - 1
        res += 10 * (solve(x) - solve(y))
        res += 45 * (10 ** (i - 1)) * (x - y)

    x = int(s[:-1]) - 1
    res += 10 * (solve(x) - solve(10 ** (L - 2) - 1))
    res += 45 * (10 ** (L - 1)) * (x - y)
    
    for i in range(int(s[-1]) + 1):
        res += rev(int(s[:-1]))
        res += i * 10 ** (L - 1)

    return res


N = int(input())
for _ in range(N):
    l, r = map(int, input().split())
    res = solve(r) - solve(l - 1)
    print(rev(res))
0