結果

問題 No.3277 Forever Monotonic Number
ユーザー sasa8uyauya
提出日時 2025-09-19 23:53:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,401 ms / 4,000 ms
コード長 865 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,600 KB
実行使用メモリ 119,784 KB
最終ジャッジ日時 2025-09-19 23:53:40
合計ジャッジ時間 23,392 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

def c(a):
  if len(a)==0:
    return 0
  if len(a)==1:
    return 1
  while len(a)>1:
    a=list(map(int,str(sum(a))))
    if not all(a[i]<=a[i+1] for i in range(len(a)-1)):
      return 0
  return 1

def f():
  if len(q)>15:
    return
  if c(q):
    p.append(int("".join(list(map(str,q)))))
  for i in range(q[-1] if len(q)>0 else 1,10):
    q.append(i)
    f()
    q.pop()
  return

p=[]
q=[]
f()

p=sorted(p)

from bisect import bisect_left,bisect_right

T=int(input())
for _ in range(T):
  n=int(input())
  M=998244353
  while bisect_right(p,9*(n+1))-bisect_left(p,1*(n+1))==0:
    n+=1
  q=p[bisect_left(p,1*(n+1))]
  for i in range(1,10):
    if i+9*n>=q:
      a=0
      a+=(pow(10,n+1,M)-1)*pow(9,M-2,M)*i%M
      q-=i*(n+1)
      m=q//(9-i)
      a+=(pow(10,m,M)-1)*pow(9,M-2,M)*(9-i)%M
      q-=(9-i)*m
      a+=q*pow(10,m,M)
      print(a%M)
      break
0