結果

問題 No.1228 I hate XOR Matching
ユーザー 👑 obakyanobakyan
提出日時 2021-08-13 14:39:12
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,537 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 7,068 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 07:49:30
合計ジャッジ時間 4,787 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 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 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local bls, brs = bit.lshift, bit.rshift
local bxor = bit.bxor

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

local k, x = io.read("*n", "*n")
if x == 0 then
  if k == 0 then
    print("Yes") print(1) print(1)
  else
    print("Yes") print(1) print(0)
  end
  os.exit()
end
if k == 0 then x = x + 1 end

local cnt = 0
local mul = 1
while cnt < 40 do
  if mul == x then break end
  cnt = cnt + 1
  mul = mul * 2
end
if 40 <= cnt then print("No") os.exit() end
print("Yes")
local tk = k
local mul = 1
local t = {}
for i = 1, 40 do
  if #t < 6 then
    table.insert(t, mul)
  else
    if tk % 2 == 1 then
      t[6] = t[6] + mul
    end
  end
  mul = mul * 2
  tk = mfl(tk / 2)
end
if cnt == 0 then
  print(6)
  print(table.concat(t, " "))
  os.exit()
end

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 v = 0
local c = 0
local function add_func(idx)
  v = v + t[idx]
  c = c + 1
end
local function rm_func(idx)
  v = v - t[idx]
  c = c - 1
end
local function work_func()
  if 2 <= c and #t < 6 + cnt then
    table.insert(t, v)
  end
end
grayWalk(6, add_func, rm_func, work_func)
print(#t)
print(table.concat(t, " "))
0