結果

問題 No.1767 BLUE to RED
ユーザー 👑 obakyanobakyan
提出日時 2022-01-09 22:22:34
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 1,287 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 6,688 KB
実行使用メモリ 24,576 KB
最終ジャッジ日時 2024-04-26 19:55:33
合計ジャッジ時間 5,369 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 121 ms
14,848 KB
testcase_10 AC 154 ms
20,864 KB
testcase_11 AC 132 ms
14,720 KB
testcase_12 AC 122 ms
14,720 KB
testcase_13 AC 164 ms
22,912 KB
testcase_14 AC 215 ms
24,576 KB
testcase_15 AC 211 ms
24,448 KB
testcase_16 AC 211 ms
24,576 KB
testcase_17 AC 210 ms
24,576 KB
testcase_18 AC 216 ms
24,576 KB
testcase_19 AC 215 ms
24,576 KB
testcase_20 AC 217 ms
24,576 KB
testcase_21 AC 210 ms
24,576 KB
testcase_22 AC 211 ms
24,448 KB
testcase_23 AC 218 ms
24,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
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 n, m = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local t = {}
for i = 1, n - 1 do
  t[i] = {}
end
local leftmin = false
local rightmax = false
for i = 1, m do
  local b = io.read("*n")
  local lb = lower_bound(a, b)
  if 1 == lb then
    if not leftmin then leftmin = b end
  elseif n < lb then
    rightmax = b
  else
    table.insert(t[lb - 1], b)
  end
end
local ret = 0
if leftmin then
  ret = ret + a[1] - leftmin
end
if rightmax then
  ret = ret + rightmax - a[n]
end
for i = 1, n - 1 do
  if 0 < #t[i] then
    local ti = t[i]
    local lenmax = mma(ti[1] - a[i], a[i + 1] - ti[#ti])
    for j = 1, #ti - 1 do
      lenmax = mma(lenmax, ti[j + 1] - ti[j])
    end
    ret = ret + a[i + 1] - a[i] - lenmax
  end
end
ret = tostring(ret * 1LL):gsub("LL", "")
print(ret)
0