結果

問題 No.733 分身並列コーディング
ユーザー 👑 obakyan
提出日時 2020-03-27 22:18:38
言語 Lua
(LuaJit 2.1.1734355927)
結果
WA  
実行時間 -
コード長 788 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 6,820 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-02 09:38:05
合計ジャッジ時間 2,769 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

local bls, brs = bit.lshift, bit.rshift
local limit = io.read("*n")
local n = io.read("*n")
local ret = 0
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
while true do
  ret = ret + 1
  local tot = bls(1, n)
  local candpos, candval = -1, -1
  for it = 0, tot - 1 do
    local a = 0
    local tmp_it = it
    for i = 1, n do
      if tmp_it % 2 == 1 then
        a = a + t[i]
      end
      tmp_it = brs(tmp_it, 1)
    end
    if a <= limit then
      if candval < a then
        candpos, candval = it, a
      end
    end
  end
  local box = {}
  for i = 1, n do
    if candpos % 2 == 1 then
      box[i] = true
    end
    candpos = brs(candpos, 1)
  end
  for i = n, 1, -1 do
    if box[i] then table.remove(t, i) end
  end
  n = #t
  if #t == 0 then break end
end
print(ret)
0