結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー 👑 obakyanobakyan
提出日時 2021-12-31 20:33:10
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,002 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 5,504 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 08:31:01
合計ジャッジ時間 2,056 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 WA -
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 1 ms
5,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 18 ms
5,376 KB
testcase_38 AC 18 ms
5,376 KB
testcase_39 AC 18 ms
5,376 KB
testcase_40 AC 15 ms
5,376 KB
testcase_41 AC 10 ms
5,376 KB
testcase_42 AC 19 ms
5,376 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 19 ms
5,376 KB
testcase_46 AC 19 ms
5,376 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 19 ms
5,376 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 20 ms
5,376 KB
testcase_55 WA -
testcase_56 AC 18 ms
5,376 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 = {}
local v = 0
for i = 1, n do
  a[i] = io.read("*n")
  v = v - a[i]
end

local cnt = 0
local function add_func(idx)
  v = v + a[idx] * 2
  cnt = cnt + 1
end
local function rm_func(idx)
  v = v - a[idx] * 2
  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