結果

問題 No.1017 Reiwa Sequence
ユーザー 👑 obakyanobakyan
提出日時 2022-08-10 00:02:25
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,496 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 40,404 KB
最終ジャッジ日時 2023-10-20 09:29:15
合計ジャッジ時間 33,964 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
35,568 KB
testcase_01 AC 23 ms
35,268 KB
testcase_02 AC 23 ms
35,572 KB
testcase_03 AC 27 ms
35,572 KB
testcase_04 AC 22 ms
35,572 KB
testcase_05 AC 22 ms
35,572 KB
testcase_06 AC 22 ms
35,572 KB
testcase_07 AC 22 ms
35,572 KB
testcase_08 AC 23 ms
35,572 KB
testcase_09 AC 27 ms
35,576 KB
testcase_10 AC 26 ms
35,576 KB
testcase_11 AC 27 ms
35,576 KB
testcase_12 AC 27 ms
35,576 KB
testcase_13 AC 26 ms
35,576 KB
testcase_14 AC 22 ms
35,268 KB
testcase_15 AC 22 ms
35,268 KB
testcase_16 AC 22 ms
35,268 KB
testcase_17 AC 23 ms
35,268 KB
testcase_18 AC 22 ms
35,268 KB
testcase_19 AC 42 ms
35,268 KB
testcase_20 AC 42 ms
35,268 KB
testcase_21 AC 39 ms
35,268 KB
testcase_22 AC 41 ms
35,268 KB
testcase_23 AC 42 ms
35,268 KB
testcase_24 AC 46 ms
35,268 KB
testcase_25 AC 42 ms
35,268 KB
testcase_26 AC 40 ms
35,268 KB
testcase_27 AC 43 ms
35,576 KB
testcase_28 AC 38 ms
35,576 KB
testcase_29 AC 27 ms
35,576 KB
testcase_30 AC 28 ms
35,576 KB
testcase_31 AC 30 ms
35,576 KB
testcase_32 AC 37 ms
35,576 KB
testcase_33 AC 27 ms
35,576 KB
testcase_34 AC 44 ms
35,576 KB
testcase_35 AC 23 ms
35,572 KB
testcase_36 AC 28 ms
35,572 KB
testcase_37 AC 46 ms
35,576 KB
testcase_38 AC 22 ms
35,572 KB
testcase_39 AC 39 ms
35,576 KB
testcase_40 AC 69 ms
38,132 KB
testcase_41 AC 68 ms
38,132 KB
testcase_42 AC 64 ms
38,116 KB
testcase_43 AC 65 ms
38,124 KB
testcase_44 AC 46 ms
38,004 KB
testcase_45 AC 67 ms
38,124 KB
testcase_46 AC 70 ms
38,116 KB
testcase_47 AC 67 ms
38,116 KB
testcase_48 AC 72 ms
40,404 KB
testcase_49 AC 62 ms
40,276 KB
testcase_50 AC 63 ms
40,276 KB
testcase_51 AC 22 ms
35,268 KB
testcase_52 AC 40 ms
35,576 KB
testcase_53 AC 34 ms
35,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local bxor = bit.bxor

local function grayCode(x)
  return bxor(x, brs(x, 1))
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 n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
-- 150000 * 22 < 2^22
local m = mmi(22, n)

local t = {}
local lim = 22 * 150000
for i = 1, lim do
  t[i] = false
end
local v = 0
local z = 0
local function add_func(idx)
  v = v + a[idx]
  z = z + bls(1, idx - 1)
end
local function rm_func(idx)
  v = v - a[idx]
  z = z - bls(1, idx - 1)
end
local function work_func()
  if t[v] then
    print("Yes")
    local ans = {}
    local x, y = t[v], z
    for i = 1, m do
      if x % 2 == 1 and y % 2 == 1 then
        ans[i] = 0
      elseif x % 2 == 1 then
        ans[i] = a[i]
      elseif y % 2 == 1 then
        ans[i] = -a[i]
      else
        ans[i] = 0
      end
      x = brs(x, 1)
      y = brs(y, 1)
    end
    for i = m + 1, n do
      ans[i] = 0
    end
    print(table.concat(ans, " "))
    os.exit()
  else
    t[v] = z
  end
end
grayWalk(m, add_func, rm_func, work_func)
print("No")
0