結果
| 問題 |
No.1228 I hate XOR Matching
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2021-08-13 14:39:12 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,537 bytes |
| コンパイル時間 | 126 ms |
| コンパイル使用メモリ | 7,072 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-03 04:57:52 |
| 合計ジャッジ時間 | 4,606 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 WA * 1 |
ソースコード
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, " "))