結果
問題 | 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 = 1000000007local function badd(a, b) return (a + b) % mod endlocal s = io.read()local d = io.read("*n")local base = 0local qcnt = 0for i = 1, #s dolocal ss = s:sub(i, i)if ss == "?" thenqcnt = qcnt + 1elsebase = base + ss:byte(1) - 48endendif qcnt == 0 thenif base == 0 thenprint(d == 0 and 1 or 0)elsebase = base % 9if base == 0 then base = 9 endprint(d == base and 1 or 0)endos.exit()endlocal dp1, dp2 = {}, {}for i = 0, 8 dodp1[i] = 0enddp1[0] = 1for iq = 1, qcnt dolocal src = iq % 2 == 1 and dp1 or dp2local dst = iq % 2 == 1 and dp2 or dp1for i = 0, 8 dodst[i] = 0endfor i = 0, 8 dofor j = 0, 9 dolocal z = (i + j) % 9dst[z] = badd(dst[z], src[i])endendendlocal tbl = qcnt % 2 == 1 and dp2 or dp1local ans = {}for i = 0, 8 do-- print(i, tbl[i])local z = (i + base) % 9ans[z] = tbl[i]endif base == 0 thenans[9] = (ans[0] + mod - 1) % modans[0] = 1elseans[9] = ans[0]ans[0] = 0endprint(ans[d])