結果
問題 | No.1267 Stop and Coin Game |
ユーザー |
👑 |
提出日時 | 2022-09-30 00:05:19 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 917 ms / 2,000 ms |
コード長 | 1,862 bytes |
コンパイル時間 | 407 ms |
コンパイル使用メモリ | 6,688 KB |
実行使用メモリ | 47,016 KB |
最終ジャッジ日時 | 2024-12-22 18:36:39 |
合計ジャッジ時間 | 8,770 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
local bls, brs = bit.lshift, bit.rshiftlocal ffi = require("ffi")local C = ffi.Cffi.cdef[[long long atoll(const char*);]]local function lltonumber(str)return C.atoll(str)endlocal asum = 0LLlocal function bdp_prepare(n, cost, lim)local tot = bls(1, n)local alltask = {}local stagetask = {}for i = 1, n dostagetask[i] = {}endfor i = 1, tot - 1 dolocal z = asumlocal ti = ilocal cnt = 0for j = 1, n doif ti % 2 == 1 thencnt = cnt + 1z = z - cost[j]endti = brs(ti, 1)endtable.insert(stagetask[cnt], i)if lim < z thenalltask[i] = 0elsealltask[i] = 1end-- print(i, z, lim, z <= lim)endreturn tot, alltask, stagetaskendlocal function bdp_doall(n, alltask, stagetask, cost, lim)for stage = 1, n dolocal stlen = #stagetask[stage]for i_stagetask = 1, stlen dolocal used = stagetask[stage][i_stagetask]-- print(used, alltask[used])if alltask[used] == 1 thenalltask[used] = falseendif not alltask[used] thenlocal mul = 1local tmp = usedfor j = 1, n doif tmp % 2 == 0 thenalltask[used + mul] = trueendtmp = brs(tmp, 1)mul = mul * 2endendendendendlocal function bdp_getresult(tot, alltask)return alltask[tot - 1]endlocal n, v = io.read():match("(%d+) (%d+)")n = tonumber(n)v = lltonumber(v)local s = io.read()local a = {}for w in s:gmatch("%d+") dolocal z = lltonumber(w)table.insert(a, z)endfor i = 1, n do asum = asum + a[i] endif asum <= v thenprint("Draw")os.exit()endlocal tot, alltask, stagetask = bdp_prepare(n, a, v)bdp_doall(n, alltask, stagetask, a, v)local ret = alltask[tot - 1]print(ret and "First" or "Second")