結果

問題 No.1267 Stop and Coin Game
ユーザー 👑 obakyanobakyan
提出日時 2022-09-30 00:05:19
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,013 ms / 2,000 ms
コード長 1,862 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 5,300 KB
実行使用メモリ 58,804 KB
最終ジャッジ日時 2023-08-24 05:12:32
合計ジャッジ時間 10,029 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 97 ms
9,096 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 983 ms
58,684 KB
testcase_11 AC 154 ms
14,936 KB
testcase_12 AC 24 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 992 ms
58,704 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 450 ms
30,168 KB
testcase_25 AC 492 ms
30,076 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 21 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 960 ms
58,804 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 94 ms
9,084 KB
testcase_33 AC 445 ms
30,072 KB
testcase_34 AC 466 ms
30,168 KB
testcase_35 AC 955 ms
58,788 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 102 ms
9,160 KB
testcase_38 AC 1,013 ms
58,668 KB
testcase_39 AC 48 ms
5,640 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 50 ms
5,780 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 109 ms
9,096 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local bls, brs = bit.lshift, bit.rshift
local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
long long atoll(const char*);
]]

local function lltonumber(str)
  return C.atoll(str)
end

local asum = 0LL

local function bdp_prepare(n, cost, lim)
  local tot = bls(1, n)
  local alltask = {}
  local stagetask = {}
  for i = 1, n do
    stagetask[i] = {}
  end
  for i = 1, tot - 1 do
    local z = asum
    local ti = i
    local cnt = 0
    for j = 1, n do
      if ti % 2 == 1 then
        cnt = cnt + 1
        z = z - cost[j]
      end
      ti = brs(ti, 1)
    end
    table.insert(stagetask[cnt], i)
    if lim < z then
      alltask[i] = 0
    else
      alltask[i] = 1
    end
    -- print(i, z, lim, z <= lim)
  end
  return tot, alltask, stagetask
end

local function bdp_doall(n, alltask, stagetask, cost, lim)
  for stage = 1, n do
    local stlen = #stagetask[stage]
    for i_stagetask = 1, stlen do
      local used = stagetask[stage][i_stagetask]
      -- print(used, alltask[used])
      if alltask[used] == 1 then
        alltask[used] = false
      end
      if not alltask[used] then
        local mul = 1
        local tmp = used
        for j = 1, n do
          if tmp % 2 == 0 then
            alltask[used + mul] = true
          end
          tmp = brs(tmp, 1)
          mul = mul * 2
        end
      end
    end
  end
end

local function bdp_getresult(tot, alltask)
  return alltask[tot - 1]
end

local 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+") do
  local z = lltonumber(w)
  table.insert(a, z)
end

for i = 1, n do asum = asum + a[i] end
if asum <= v then
  print("Draw")
  os.exit()
end

local 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")
0