結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー 👑 obakyanobakyan
提出日時 2021-12-31 20:32:00
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 979 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 08:30:00
合計ジャッジ時間 1,983 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 WA -
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,948 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 WA -
testcase_22 AC 1 ms
6,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 1 ms
6,944 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1 ms
6,944 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 20 ms
6,940 KB
testcase_38 AC 20 ms
6,944 KB
testcase_39 AC 20 ms
6,940 KB
testcase_40 AC 8 ms
6,940 KB
testcase_41 AC 20 ms
6,940 KB
testcase_42 AC 20 ms
6,944 KB
testcase_43 AC 1 ms
6,940 KB
testcase_44 AC 1 ms
6,944 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 6 ms
6,944 KB
testcase_50 AC 20 ms
6,944 KB
testcase_51 AC 21 ms
6,944 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 20 ms
6,940 KB
testcase_55 WA -
testcase_56 AC 20 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local bls, brs = bit.lshift, bit.rshift
local bxor = bit.bxor

local function grayCode(x)
  return bxor(x, brs(x, 1))
end

-- add_func(idx), rm_func(idx), work_func()
local function grayWalk(size, add_func, rm_func, work_func)
  local prv = 0
  local total = bls(1, size) - 1
  local bpos = {}
  for i = 1, size do
    bpos[bls(1, i - 1)] = i
  end
  -- work_func()
  for i = 1, total do
    local v = grayCode(i)
    if prv < v then
      prv, v = v, v - prv
      add_func(bpos[v])
    else
      prv, v = v, prv - v
      rm_func(bpos[v])
    end
    work_func()
  end
end

local n, k = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end

local cnt = 0
local v = 0
local function add_func(idx)
  v = v + a[idx]
  cnt = cnt + 1
end
local function rm_func(idx)
  v = v - a[idx]
  cnt = cnt - 1
end
local function work_func()
  if cnt < n then
    if v == k then print("Yes") os.exit() end
  end
end
grayWalk(n, add_func, rm_func, work_func)
print("No")
0