結果

問題 No.8133 ‮Reversed‪
コンテスト
ユーザー lif4635
提出日時 2026-04-01 21:54:00
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,457 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 318 ms
コンパイル使用メモリ 84,644 KB
実行使用メモリ 168,828 KB
最終ジャッジ日時 2026-04-01 21:54:13
合計ジャッジ時間 12,106 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 4 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

mod = 7000000001

p = [pow(10, i, mod) for i in range(40)]

def calc(x):
    # print(x)
    if x <= 0:
        return 0
        
    s = str(x)
    n = len(s)
    
    ans = 0
    for l in range(1, n):
        ans += 45 * p[l - 1] % mod
        if l > 1:
            ans += 45 * p[l - 2] * (p[l] - 10) % mod
    
    dpc = [0, 0]
    dps = [0, 0]
    
    for i in range(n):
        ndpc = [0, 0]
        ndps = [0, 0]
        lim = int(s[i])
        
        if i == 0:
            for d in range(1, lim + 1):
                sm = int(d < lim)
                ndpc[sm] += 1
                ndps[sm] += d
        else:
            for sm in range(2):
                if dpc[sm] == 0:
                    continue
                limd = 9 if sm else lim
                for d in range(limd + 1):
                    nsm = sm | int(d < limd)
                    ndpc[nsm] += dpc[sm] % mod
                    ndps[nsm] += dps[sm] + d * p[i]  % mod * dpc[sm] % mod
                    
        dpc = ndpc
        dps = ndps
    
    # print(ans + sum(dps))
    return ans + sum(dps)


# print(calc(62) - calc(19))

# for i in range(4):
    # print(input())

# import codecs
n = int(input().replace('\u202e', '').replace('\\u202e', ''))
for i in range(n):
    l, r = [int(x.replace('\u202e', '').replace('\\u202e', '')) for x in input().split()]
    x = calc(r) - calc(l - 1)
    # print(l, r)
    x = x % mod
    print("\u202e"+str(x)[::-1]+"\n", end = "")



0