結果
問題 | No.107 モンスター |
ユーザー |
👑 |
提出日時 | 2020-03-27 22:54:38 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 38 ms / 5,000 ms |
コード長 | 1,985 bytes |
コンパイル時間 | 80 ms |
コンパイル使用メモリ | 6,952 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-02 09:45:06 |
合計ジャッジ時間 | 1,332 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
local bls, brs = bit.lshift, bit.rshiftlocal mfl, mce = math.floor, math.ceillocal mmi, mma = math.min, math.maxlocal n = io.read("*n")local cost = {}for i = 1, n docost[i] = io.read("*n")endlocal maxhp = {}local tot = bls(1, n)for i = 1, tot - 1 dolocal lv = 1local ti = ifor j = 1, n doif ti % 2 == 1 thenif cost[j] < 0 thenlv = lv + 1endendti = brs(ti, 1)endmaxhp[i] = 100 * lvendlocal function bdp_prepare()local alltask = {}local stagetask = {}for i = 1, n dostagetask[i] = {}endfor i = 1, tot - 1 doalltask[i] = 0endfor i = 1, tot - 1 dolocal ti = ilocal cnt = 0for j = 1, n doif ti % 2 == 1 thencnt = cnt + 1ti = ti - 1endti = ti / 2endtable.insert(stagetask[cnt], i)end-- set first statelocal tmp = 1for i = 1, n doif cost[i] < 0 thenalltask[tmp] = mma(0, 100 + cost[i])elsealltask[tmp] = 100endtmp = tmp * 2endreturn alltask, stagetaskendlocal function bdp_doall(alltask, stagetask)for stage = 1, n - 1 dolocal stlen = #stagetask[stage]for i_stagetask = 1, stlen dolocal used = stagetask[stage][i_stagetask]local mul = 1local tmp = usedif 0 < alltask[used] thenfor j = 1, n doif tmp % 2 == 0 thenlocal nxt = 0if cost[j] < 0 thennxt = mma(0, alltask[used] + cost[j])elsenxt = mmi(maxhp[used], alltask[used] + cost[j])endalltask[used + mul] = mma(alltask[used + mul], nxt)elsetmp = tmp - 1endtmp = tmp / 2mul = mul * 2endendendendendlocal function bdp_getresult(alltask)return alltask[tot - 1]endlocal alltask, stagetask = bdp_prepare()bdp_doall(alltask, stagetask)local ret = bdp_getresult(alltask)print(ret)