結果

問題 No.822 Bitwise AND
ユーザー 👑 obakyanobakyan
提出日時 2019-04-26 22:30:10
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
実行時間 -
コード長 1,024 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-05-03 23:36:04
合計ジャッジ時間 6,583 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

local n, k = io.read("*n", "*n")
-- 2^a + n - (2^a - 1) <= k
if(n < k) then print("INF")
else
  local len = 0
  local lastzero = -1
  local zeropos = {}
  local tmpn = n
  while(0 < tmpn) do
    len = len + 1
    local s = tmpn % 2
    if(s == 0) then
      lastzero = len
      table.insert(zeropos, len)
    end
    tmpn = math.floor(tmpn / 2)
  end
  if(lastzero == -1) then
    print(1)
  else
    local allcnt = 0
    local a_base = 2^(lastzero - 1)
    local arb_count = #zeropos - 1
    local iter = 3^arb_count
    for i = 0, iter do
      local i_tmp = i
      local a_cand = a_base
      local b_cand = 0
      local mult = 1
      while(0 < i_tmp) do
        local s = i_tmp % 3
        if(s == 0) then a_cand = a_cand + 2^(zeropos[mult] - 1)
        elseif(s == 1) then b_cand = b_cand + 2^(zeropos[mult] - 1)
        end
        mult = mult + 1
        i_tmp = math.floor(i_tmp / 3)
      end
      local flg = a_cand - b_cand <= k
      if(flg) then allcnt = allcnt + 1 end
    end
    print(allcnt)
  end
end
0