結果

問題 No.1417 100の倍数かつ正整数(2)
ユーザー 👑 obakyanobakyan
提出日時 2021-08-11 22:16:17
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 10 ms / 3,000 ms
コード長 1,594 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 00:14:06
合計ジャッジ時間 1,480 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 6 ms
4,348 KB
testcase_34 AC 9 ms
4,348 KB
testcase_35 AC 8 ms
4,348 KB
testcase_36 AC 9 ms
4,348 KB
testcase_37 AC 10 ms
4,348 KB
testcase_38 AC 9 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mod = 1000000007
local function badd(a, b) return (a + b) % mod end
local s = io.read()
--[[
1: 1
2: 2
3: 4
4: 5
5: 10
6: 20
7: 25
8: 50
9: 100
]]

local t = {}
t[1] = {1, 2, 3, 4, 5, 6, 7, 8, 9}
t[2] = {2, 3, 3, 5, 6, 6, 8, 9, 9}
t[3] = {}
t[4] = {3, 3, 3, 6, 6, 6, 9, 9, 9}
t[5] = {4, 5, 6, 7, 8, 9, 7, 8, 9}
t[6] = {}
t[7] = {}
t[8] = {}
t[9] = {}
for i = 1, 9 do
  t[3][i] = t[1][i]
  t[6][i] = t[2][i]
  t[7][i] = t[1][i]
  t[8][i] = t[4][i]
  t[9][i] = t[1][i]
end

local dp1, dp2 = {}, {}
for i = 1, 9 do
  dp1[i] = 0
end

local maxstate = 1
local sn = #s
for i = 1, sn do
  local ss = s:byte(i) - 48
  local src = i % 2 == 1 and dp1 or dp2
  local dst = i % 2 == 1 and dp2 or dp1
  for j = 1, 9 do
    dst[j] = 0
  end
  local lim = i == 1 and ss - 1 or 9
  for j = 1, lim do
    local z = t[j][1]
    dst[z] = dst[z] + 1
  end
  if ss == 0 then
    maxstate = 0
    for j = 1, 9 do
      for k = 1, 9 do
        local z = t[k][j]
        dst[z] = badd(dst[z], src[j])
      end
    end
  else
    if 0 < maxstate then
      if 1 < i then
        for j = 1, ss - 1 do
          local z = t[j][maxstate]
          dst[z] = badd(dst[z], 1)
        end
      end
      maxstate = t[ss][maxstate]
    end
    for j = 1, 9 do
      for k = 1, 9 do
        local z = t[k][j]
        dst[z] = badd(dst[z], src[j])
      end
    end
  end
  -- print("- " .. maxstate)
  -- print("SRC" .. " " .. table.concat(src, " "))
  -- print("DST" .. " " .. table.concat(dst, " "))
end
local tbl = sn % 2 == 1 and dp2 or dp1
local ret = tbl[9]
if maxstate == 9 then ret = badd(ret, 1) end
print(ret)
0