結果
問題 | No.1538 引きこもりさんは引き算が得意。 |
ユーザー | 👑 obakyan |
提出日時 | 2021-12-31 23:07:18 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,607 bytes |
コンパイル時間 | 124 ms |
コンパイル使用メモリ | 5,120 KB |
実行使用メモリ | 5,404 KB |
最終ジャッジ日時 | 2024-10-09 05:46:15 |
合計ジャッジ時間 | 1,955 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 10 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 6 ms
5,248 KB |
testcase_15 | WA | - |
testcase_16 | AC | 3 ms
5,248 KB |
testcase_17 | AC | 4 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 1 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 1 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 1 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 4 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 1 ms
5,248 KB |
testcase_31 | AC | 2 ms
5,248 KB |
testcase_32 | AC | 1 ms
5,248 KB |
testcase_33 | AC | 1 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 1 ms
5,248 KB |
testcase_37 | AC | 17 ms
5,248 KB |
testcase_38 | AC | 14 ms
5,248 KB |
testcase_39 | AC | 18 ms
5,248 KB |
testcase_40 | AC | 7 ms
5,248 KB |
testcase_41 | AC | 7 ms
5,248 KB |
testcase_42 | WA | - |
testcase_43 | AC | 10 ms
5,248 KB |
testcase_44 | AC | 7 ms
5,248 KB |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | AC | 5 ms
5,248 KB |
testcase_48 | AC | 27 ms
5,396 KB |
testcase_49 | AC | 8 ms
5,248 KB |
testcase_50 | AC | 7 ms
5,248 KB |
testcase_51 | AC | 28 ms
5,396 KB |
testcase_52 | AC | 23 ms
5,260 KB |
testcase_53 | AC | 17 ms
5,396 KB |
testcase_54 | AC | 28 ms
5,396 KB |
testcase_55 | AC | 16 ms
5,404 KB |
testcase_56 | AC | 29 ms
5,400 KB |
ソースコード
local mmi, mma = math.min, math.max local bls, brs = bit.lshift, bit.rshift local bxor = bit.bxor local bor, band = bit.bor, bit.band -- work_func(idx) -- v = [0, 1, 2] local function grayWalk3(size, work_func, box) assert(size <= 15) local prv = 0 local total = 3^size - 1 local rep = 3^(size-1) local bpos = {} for i = 1, size do bpos[bls(1, i - 1)] = i end local v2 = 0 for i = 1, size do box[i] = 0 end local function incOne() if box[1] == 0 then box[1] = 1 v2 = v2 + 1 elseif box[1] == 1 then box[1] = 2 else box[1] = 0 v2 = v2 - 1 end work_func(1) end local function incX() local z = band(v2, -v2) * 2 local p = bpos[z] if box[p] == 0 then box[p] = 1 v2 = v2 + z elseif box[p] == 1 then box[p] = 2 else box[p] = 0 v2 = v2 - z end work_func(p) end work_func(1) incOne() incOne() for i = 1, rep - 1 do incX() incOne() incOne() 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 large = 10 < n local tail_allplus, tail_allminus = false, false local tail = {} local graybox = {} if large then local tn = n - 10 local v = 0 local cnt1 = 0 local cnt2 = 0 local function work_func(idx) if graybox[idx] == 0 then if 0 < cnt2 then cnt2 = cnt2 - 1 v = v - a[10 + idx] end elseif graybox[idx] == 1 then cnt1 = cnt1 + 1 v = v - a[10 + idx] else cnt1 = cnt1 - 1 cnt2 = cnt2 + 1 v = v + 2 * a[10 + idx] end if cnt1 == tn then tail_allminus = v elseif cnt2 == tn then tail_allplus = v else tail[v] = true end end grayWalk3(tn, work_func, graybox) end local function finish() print("Yes") os.exit() end if tail[k] then finish() end do local tn = mmi(10, n) local v = 0 local cnt1 = 0 local cnt2 = 0 local function work_func(idx) if graybox[idx] == 0 then if 0 < cnt2 then cnt2 = cnt2 - 1 v = v - a[idx] end elseif graybox[idx] == 1 then cnt1 = cnt1 + 1 v = v - a[idx] else cnt1 = cnt1 - 1 cnt2 = cnt2 + 1 v = v + 2 * a[idx] end local z = k - v if tail[z] then finish() end if 0 < cnt1 then if tail_allplus == z then finish() end end if 0 < cnt2 then if tail_allminus == z then finish() end end if 0 < cnt1 + cnt2 then if z == 0 then finish() end end end grayWalk3(tn, work_func, graybox) end print("No")