結果
| 問題 |
No.1651 Removing Cards
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-11-07 21:31:11 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 1,958 ms / 2,000 ms |
| コード長 | 2,543 bytes |
| コンパイル時間 | 202 ms |
| コンパイル使用メモリ | 5,248 KB |
| 実行使用メモリ | 53,680 KB |
| 最終ジャッジ日時 | 2024-11-07 21:31:47 |
| 合計ジャッジ時間 | 32,383 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
local pow2 = {1}
for i = 2, 28 do pow2[i] = pow2[i - 1] * 2 end
local function mergesort(ary, buf, sortfunc)
local n = #ary
local rep, mul = 0, 1
while mul < n do
rep, mul = rep + 1, mul * 2
end
for irep = 1, rep do
local src = irep % 2 == 1 and ary or buf
local dst = irep % 2 == 1 and buf or ary
local sz = pow2[irep]
local boxcnt = pow2[rep - irep + 1]
for i = 1, boxcnt do
local il = 1 + sz * 2 * (i - 1)
local ir = il + sz
local llim = ir - 1
local rlim = llim + sz
local id = il
local rem = sz * 2
if n <= llim then
for k = il, n do dst[k] = src[k] end
break
elseif n <= rlim then
rlim = n
rem = n - il + 1
end
for j = 1, rem do
if sortfunc(src[ir], src[il]) then
dst[id] = src[ir] ir = ir + 1
else
dst[id] = src[il] il = il + 1
end
id = id + 1
if llim < il then
for k = 0, rem - j - 1 do dst[id + k] = src[ir + k] end
break
elseif rlim < ir then
for k = 0, rem - j - 1 do dst[id + k] = src[il + k] end
break
end
end
end
end
-- local sorted_tbl_is_written_in_ary1 = rep % 2 == 0
return rep % 2 == 0
end
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 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
-- print(t[1])
-- print(#t, t[#t])
-- os.exit()
local a = {}
local aidx = {}
local ans = {}
for iq = 1, q do
aidx[iq] = iq
local z = io.read()
z = string.rep("0", 19 - #z) .. z
a[iq] = z
ans[iq] = 0
end
local buf = {}
local f = mergesort(aidx, buf, function(x, y) return a[x] < a[y] end)
if not f then aidx = buf end
local tpos = 1
for iq = 1, q do
local i = aidx[iq]
local n = lltonumber(a[i])
if n == 1LL then
ans[i] = 1
else
while tpos <= #t and t[tpos] < n do
tpos = tpos + 1
end
if tpos == 1 then
ans[i] = 2
else
ans[i] = tostring(t[tpos - 1] + 1LL):gsub("LL", "")
end
end
end
print(table.concat(ans, "\n"))