結果

問題 No.1407 Kindness
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-03-01 15:15:57
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,264 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,792 KB
実行使用メモリ 74,016 KB
最終ジャッジ日時 2024-04-14 03:43:25
合計ジャッジ時間 3,603 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,556 KB
testcase_01 AC 41 ms
59,776 KB
testcase_02 AC 37 ms
53,136 KB
testcase_03 AC 36 ms
52,948 KB
testcase_04 AC 37 ms
53,288 KB
testcase_05 AC 37 ms
52,396 KB
testcase_06 AC 37 ms
53,120 KB
testcase_07 AC 37 ms
52,328 KB
testcase_08 AC 37 ms
53,636 KB
testcase_09 AC 37 ms
53,212 KB
testcase_10 AC 41 ms
52,952 KB
testcase_11 AC 37 ms
53,132 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 73 ms
74,016 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 70 ms
71,704 KB
testcase_37 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main1(n):
  mod=10**9+7
  # n<=pow(10,10**5)
  """
  2345
  1つ目:0,1,2
  2つ目:0~9,0~9,0,1,2,3
  3つ目:0~9,..,0~9,0,1,2,3,4
  4つ目:0~9,...0~9,0,1,2,3,4,5
  """
  ary=list(map(int,list(str(n))))
  m=len(ary)
  dp0=[[0]*10 for _ in range(m)] # nぴったり
  dp1=[[0]*10 for _ in range(m)] # n未満
  # dp[i][j]:左からi桁目がjであるものの桁積の合計
  for i in range(ary[0]):dp1[0][i]=i
  dp0[0][ary[0]]=ary[0]
  for i in range(m-1):
    for j in range(1,10):# 左からi桁目がjのものから
      for k in range(1,10):# 左からi+1桁目がkのものへ遷移
        if j==ary[i]:# ぴったりから
          if k==ary[i+1]:# ぴったりへ遷移
            dp0[i+1][k]+=dp0[i][j]*k
            dp0[i+1][k]%=mod
          elif k<ary[i+1]:# 未満へ遷移
            dp1[i+1][k]+=dp0[i][j]*k
            dp1[i+1][k]%=mod
        #else:
        # 未満から未満へ遷移
        dp1[i+1][k]+=dp1[i][j]*k
        dp1[i+1][k]%=mod
    # 0~i桁目がすべて0のものからi+1桁目がkのものへ遷移
    for k in range(1,10):dp1[i+1][k]+=k
    
  ret=0
  for i in range(10):
    ret+=dp0[-1][i]
    ret+=dp1[-1][i]
    ret%=mod
  return ret

if __name__=='__main__':
  n=int(input())
  ret1=main1(n)
  print(ret1)
0