結果
問題 | No.1651 Removing Cards |
ユーザー | 👑 obakyan |
提出日時 | 2024-11-07 21:20:18 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,553 bytes |
コンパイル時間 | 117 ms |
コンパイル使用メモリ | 5,376 KB |
実行使用メモリ | 46,068 KB |
最終ジャッジ日時 | 2024-11-07 21:20:57 |
合計ジャッジ時間 | 35,382 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 357 ms
11,648 KB |
testcase_03 | AC | 3 ms
5,248 KB |
testcase_04 | AC | 3 ms
5,248 KB |
testcase_05 | AC | 3 ms
5,248 KB |
testcase_06 | AC | 3 ms
5,248 KB |
testcase_07 | AC | 3 ms
5,248 KB |
testcase_08 | AC | 4 ms
5,248 KB |
testcase_09 | AC | 210 ms
18,324 KB |
testcase_10 | AC | 211 ms
18,360 KB |
testcase_11 | AC | 208 ms
18,360 KB |
testcase_12 | AC | 218 ms
18,468 KB |
testcase_13 | AC | 205 ms
18,352 KB |
testcase_14 | AC | 218 ms
18,372 KB |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | AC | 1,997 ms
41,992 KB |
testcase_18 | AC | 1,900 ms
39,492 KB |
testcase_19 | TLE | - |
testcase_20 | AC | 1,779 ms
41,996 KB |
testcase_21 | AC | 1,919 ms
39,716 KB |
testcase_22 | TLE | - |
testcase_23 | AC | 215 ms
19,156 KB |
testcase_24 | AC | 198 ms
16,344 KB |
testcase_25 | AC | 1,935 ms
38,756 KB |
testcase_26 | AC | 1,803 ms
37,384 KB |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | AC | 1,975 ms
40,320 KB |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | AC | 147 ms
14,016 KB |
testcase_33 | AC | 150 ms
15,232 KB |
testcase_34 | AC | 150 ms
15,232 KB |
ソースコード
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 a[iq] = lltonumber(io.read()) 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 -- 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"))