結果

問題 No.3277 Forever Monotonic Number
ユーザー lif4635
提出日時 2025-09-06 00:43:09
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 698 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 79,860 KB
最終ジャッジ日時 2025-09-06 00:45:23
合計ジャッジ時間 6,427 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 TLE * 2 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353

def check(x):
    x = str(x)
    l = len(x)
    if l == 1: return True
    for i in range(l-1):
        if x[i] > x[i+1]: return False
    return check(sum(map(int, x)))

for i in range(int(input())):
    d = int(input()) + 1
    n = str(d)
    l = len(n)
    m = n[0]
    for i in range(1, l):
        if m[-1] <= n[i]:
            m += n[i]
        else:
            m += m[-1] * (l - i)
            break
    m = int(m)
    while check(m) == False:
        m += 1
    
    m -= d
    ans = (pow(10, d, mod) - 1) * pow(9, -1, mod) % mod
    p, q = divmod(m, 8)
    ans += 8 * (pow(10, p, mod) - 1) * pow(9, -1, mod) % mod
    ans += q * pow(10, p, mod) % mod
    print(ans % mod)
0