結果
| 問題 | No.1085 桁和の桁和 | 
| コンテスト | |
| ユーザー | 👑 | 
| 提出日時 | 2021-08-08 16:10:26 | 
| 言語 | Lua (LuaJit 2.1.1734355927) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 79 ms / 2,000 ms | 
| コード長 | 1,059 bytes | 
| コンパイル時間 | 181 ms | 
| コンパイル使用メモリ | 5,376 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-19 12:30:19 | 
| 合計ジャッジ時間 | 3,091 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 35 | 
ソースコード
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])
            
            
            
        