結果
問題 | No.1017 Reiwa Sequence |
ユーザー | obakyan |
提出日時 | 2022-08-10 00:02:25 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 1,496 bytes |
コンパイル時間 | 209 ms |
コンパイル使用メモリ | 6,944 KB |
実行使用メモリ | 40,192 KB |
最終ジャッジ日時 | 2024-09-20 04:57:11 |
合計ジャッジ時間 | 32,698 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
35,392 KB |
testcase_01 | AC | 23 ms
35,412 KB |
testcase_02 | AC | 22 ms
35,412 KB |
testcase_03 | AC | 28 ms
35,416 KB |
testcase_04 | AC | 22 ms
35,496 KB |
testcase_05 | AC | 22 ms
35,352 KB |
testcase_06 | AC | 22 ms
35,504 KB |
testcase_07 | AC | 22 ms
35,348 KB |
testcase_08 | AC | 22 ms
35,456 KB |
testcase_09 | AC | 29 ms
35,352 KB |
testcase_10 | AC | 28 ms
35,456 KB |
testcase_11 | AC | 28 ms
35,456 KB |
testcase_12 | AC | 28 ms
35,528 KB |
testcase_13 | AC | 28 ms
35,564 KB |
testcase_14 | AC | 23 ms
35,328 KB |
testcase_15 | AC | 23 ms
35,444 KB |
testcase_16 | AC | 23 ms
35,368 KB |
testcase_17 | AC | 23 ms
35,364 KB |
testcase_18 | AC | 22 ms
35,456 KB |
testcase_19 | AC | 36 ms
35,416 KB |
testcase_20 | AC | 43 ms
35,420 KB |
testcase_21 | AC | 38 ms
35,328 KB |
testcase_22 | AC | 37 ms
35,584 KB |
testcase_23 | AC | 37 ms
35,268 KB |
testcase_24 | AC | 38 ms
35,456 KB |
testcase_25 | AC | 39 ms
35,412 KB |
testcase_26 | AC | 36 ms
35,388 KB |
testcase_27 | AC | 41 ms
35,512 KB |
testcase_28 | AC | 37 ms
35,456 KB |
testcase_29 | AC | 28 ms
35,584 KB |
testcase_30 | AC | 28 ms
35,516 KB |
testcase_31 | AC | 31 ms
35,368 KB |
testcase_32 | AC | 36 ms
35,584 KB |
testcase_33 | AC | 28 ms
35,416 KB |
testcase_34 | AC | 39 ms
35,456 KB |
testcase_35 | AC | 22 ms
35,504 KB |
testcase_36 | AC | 28 ms
35,456 KB |
testcase_37 | AC | 41 ms
35,356 KB |
testcase_38 | AC | 22 ms
35,360 KB |
testcase_39 | AC | 36 ms
35,408 KB |
testcase_40 | AC | 70 ms
38,032 KB |
testcase_41 | AC | 68 ms
38,016 KB |
testcase_42 | AC | 68 ms
38,016 KB |
testcase_43 | AC | 74 ms
38,096 KB |
testcase_44 | AC | 46 ms
38,016 KB |
testcase_45 | AC | 71 ms
38,016 KB |
testcase_46 | AC | 69 ms
37,956 KB |
testcase_47 | AC | 65 ms
37,896 KB |
testcase_48 | AC | 72 ms
40,192 KB |
testcase_49 | AC | 64 ms
40,064 KB |
testcase_50 | AC | 65 ms
40,064 KB |
testcase_51 | AC | 22 ms
35,440 KB |
testcase_52 | AC | 37 ms
35,456 KB |
testcase_53 | AC | 34 ms
35,412 KB |
ソースコード
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")