結果

問題 No.1085 桁和の桁和
ユーザー 👑 obakyanobakyan
提出日時 2021-08-08 16:10:26
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,059 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 16:24:30
合計ジャッジ時間 3,712 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local mod = 1000000007
local function badd(a, b) return (a + b) % mod end
local s = io.read()
local d = io.read("*n")
local base = 0
local qcnt = 0
for i = 1, #s do
  local ss = s:sub(i, i)
  if ss == "?" then
    qcnt = qcnt + 1
  else
    base = base + ss:byte(1) - 48
  end
end

if qcnt == 0 then
  if base == 0 then
    print(d == 0 and 1 or 0)
  else
    base = base % 9
    if base == 0 then base = 9 end
    print(d == base and 1 or 0)
  end
  os.exit()
end
local dp1, dp2 = {}, {}
for i = 0, 8 do
  dp1[i] = 0
end
dp1[0] = 1
for iq = 1, qcnt do
  local src = iq % 2 == 1 and dp1 or dp2
  local dst = iq % 2 == 1 and dp2 or dp1
  for i = 0, 8 do
    dst[i] = 0
  end
  for i = 0, 8 do
    for j = 0, 9 do
      local z = (i + j) % 9
      dst[z] = badd(dst[z], src[i])
    end
  end
end
local tbl = qcnt % 2 == 1 and dp2 or dp1

local ans = {}
for i = 0, 8 do
  -- print(i, tbl[i])
  local z = (i + base) % 9
  ans[z] = tbl[i]
end
if base == 0 then
  ans[9] = (ans[0] + mod - 1) % mod
  ans[0] = 1
else
  ans[9] = ans[0]
  ans[0] = 0
end
print(ans[d])
0