結果
| 問題 |
No.1651 Removing Cards
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-10-23 00:05:40 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,413 bytes |
| コンパイル時間 | 673 ms |
| コンパイル使用メモリ | 6,816 KB |
| 実行使用メモリ | 35,244 KB |
| 最終ジャッジ日時 | 2024-10-23 00:06:18 |
| 合計ジャッジ時間 | 35,512 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 TLE * 5 |
ソースコード
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 x <= ary[1] then return 1 end
if 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 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())