結果

問題 No.1651 Removing Cards
ユーザー 👑 obakyanobakyan
提出日時 2021-08-20 23:33:22
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,526 ms / 2,000 ms
コード長 1,431 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 35,240 KB
最終ジャッジ日時 2024-04-22 08:14:33
合計ジャッジ時間 25,224 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 287 ms
11,648 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 93 ms
6,944 KB
testcase_10 AC 98 ms
6,940 KB
testcase_11 AC 102 ms
6,940 KB
testcase_12 AC 104 ms
6,940 KB
testcase_13 AC 104 ms
6,940 KB
testcase_14 AC 108 ms
6,940 KB
testcase_15 AC 1,449 ms
34,852 KB
testcase_16 AC 1,385 ms
34,460 KB
testcase_17 AC 1,393 ms
34,800 KB
testcase_18 AC 1,316 ms
33,708 KB
testcase_19 AC 1,335 ms
33,572 KB
testcase_20 AC 1,215 ms
33,320 KB
testcase_21 AC 1,377 ms
33,840 KB
testcase_22 AC 1,375 ms
33,692 KB
testcase_23 AC 88 ms
6,944 KB
testcase_24 AC 75 ms
6,940 KB
testcase_25 AC 1,416 ms
33,700 KB
testcase_26 AC 1,266 ms
32,420 KB
testcase_27 AC 1,526 ms
35,240 KB
testcase_28 AC 1,438 ms
34,980 KB
testcase_29 AC 1,508 ms
35,116 KB
testcase_30 AC 1,516 ms
35,172 KB
testcase_31 AC 1,524 ms
34,980 KB
testcase_32 AC 79 ms
6,940 KB
testcase_33 AC 81 ms
6,944 KB
testcase_34 AC 84 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
long long atoll(const char*);
]]

local function lltonumber(str)
  return C.atoll(str)
end

local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1], x) then return 1 end
  if comp(ary[num], x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid], x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local k, q = io.read("*n", "*n", "*l")
k = 1LL * k
local lim = 1000000007LL * 1000000007LL

local function solve(x)
  local min, max = x - 1LL, x * 2LL + 10
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local v = (mid + k - 1LL) / k
    if x + 1LL <= mid - v then
      max = mid
    else
      min = mid
    end
  end
  return max - 1LL
end

local t = {}
local sz = 1LL
while sz < lim do
  sz = solve(sz)
  table.insert(t, sz)
end
-- for i = 1, #t do
  -- print(i, t[i], ret[i])
-- end
-- print(t[1])
-- print(#t, t[#t])
-- os.exit()

for iq = 1, q do
  local n = io.read()
  n = lltonumber(n)
  if n == 1LL then
    print(1)
  else
    local pos = lower_bound(t, n)
    if pos == 1 then
      print(2)
    else
      local ans = tostring(t[pos - 1] + 1LL):gsub("LL", "")
      print(ans)
    end
  end
end
-- print(os.clock())
0