結果
問題 | No.1513 simple 門松列 problem |
ユーザー | 👑 obakyan |
提出日時 | 2022-01-10 00:24:58 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 960 ms / 3,000 ms |
コード長 | 2,353 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 7,076 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 10:38:07 |
合計ジャッジ時間 | 5,526 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 3 ms
6,820 KB |
testcase_02 | AC | 960 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 4 ms
6,820 KB |
testcase_06 | AC | 5 ms
6,820 KB |
testcase_07 | AC | 4 ms
6,816 KB |
testcase_08 | AC | 7 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 4 ms
6,820 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,820 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 928 ms
6,816 KB |
testcase_15 | AC | 937 ms
6,816 KB |
testcase_16 | AC | 943 ms
6,816 KB |
testcase_17 | AC | 591 ms
6,820 KB |
testcase_18 | AC | 193 ms
6,820 KB |
testcase_19 | AC | 18 ms
6,816 KB |
testcase_20 | AC | 120 ms
6,816 KB |
ソースコード
local mod = 998244353 local mfl = math.floor local function bmul(x, y) local x0, y0 = x % 31596, y % 31596 local x1, y1 = mfl(x / 31596), mfl(y / 31596) return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % mod end local function badd(x, y) return (x + y) % mod end local function bsub(x, y) return x < y and x - y + mod or x - y end local n, k = io.read("*n", "*n") local dp1, dp2 = {}, {} local dpsum1, dpsum2 = {}, {} for i = 1, k do dp1[i] = {} dp2[i] = {} dpsum1[i] = {} dpsum2[i] = {} end for i = 1, k do for j = 1, i - 1 do dp1[i][j] = 1 dpsum1[i][j] = i + j - 2 end dp1[i][i] = 0 dpsum1[i][i] = 0 for j = i + 1, k do dp1[i][j] = 1 dpsum1[i][j] = i + j - 2 end end for irep = 3, n do local src = irep % 2 == 1 and dp1 or dp2 local dst = irep % 2 == 1 and dp2 or dp1 local srcsum = irep % 2 == 1 and dpsum1 or dpsum2 local dstsum = irep % 2 == 1 and dpsum2 or dpsum1 for i = 1, k do for j = 1, k do dst[i][j] = 0 dstsum[i][j] = 0 end end for i = 1, k do for j = 1, i - 1 do local sij = src[i][j] local dj = dst[j] dj[j + 1] = badd(dj[j + 1], sij) dj[i] = bsub(dj[i], sij) if i < k then dj[i + 1] = badd(dj[i + 1], sij) end sij = srcsum[i][j] dj = dstsum[j] dj[j + 1] = badd(dj[j + 1], sij) dj[i] = bsub(dj[i], sij) if i < k then dj[i + 1] = badd(dj[i + 1], sij) end end for j = i + 1, k do local sij = src[i][j] local dj = dst[j] dj[1] = badd(dj[1], sij) dj[j] = bsub(dj[j], sij) dj[i] = bsub(dj[i], sij) dj[i + 1] = badd(dj[i + 1], sij) sij = srcsum[i][j] dj = dstsum[j] dj[1] = badd(dj[1], sij) dj[j] = bsub(dj[j], sij) dj[i] = bsub(dj[i], sij) dj[i + 1] = badd(dj[i + 1], sij) end end for i = 1, k do local di = dst[i] local dsi = dstsum[i] for j = 2, k do di[j] = badd(di[j], di[j - 1]) dsi[j] = badd(dsi[j], dsi[j - 1]) end for j = 2, k do dsi[j] = badd(dsi[j], bmul(j - 1, di[j])) end end end local tbl = n % 2 == 1 and dp2 or dp1 local tblsum = n % 2 == 1 and dpsum2 or dpsum1 local ret = 0 local retsum = 0 for i = 1, k do for j = 1, k do ret = badd(ret, tbl[i][j]) retsum = badd(retsum, tblsum[i][j]) end end print(ret .. " " .. retsum)