結果
| 問題 |
No.1651 Removing Cards
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-11-07 21:17:12 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,166 bytes |
| コンパイル時間 | 264 ms |
| コンパイル使用メモリ | 5,504 KB |
| 実行使用メモリ | 45,160 KB |
| 最終ジャッジ日時 | 2024-11-07 21:17:50 |
| 合計ジャッジ時間 | 37,503 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 TLE * 13 |
ソースコード
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
a[iq] = lltonumber(io.read())
ans[iq] = 0
end
table.sort(aidx, function(x, y) return a[x] < a[y] end)
local tpos = 1
for iq = 1, q do
local i = aidx[iq]
local n = 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"))