結果

問題 No.281 門松と魔法(1)
ユーザー 👑 obakyanobakyan
提出日時 2019-06-03 11:37:39
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,056 bytes
コンパイル時間 52 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 23:16:36
合計ジャッジ時間 1,618 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 1 ms
4,348 KB
testcase_46 AC 1 ms
4,348 KB
testcase_47 AC 1 ms
4,348 KB
testcase_48 AC 1 ms
4,348 KB
testcase_49 AC 1 ms
4,348 KB
testcase_50 AC 1 ms
4,348 KB
testcase_51 AC 1 ms
4,348 KB
testcase_52 AC 1 ms
4,348 KB
testcase_53 AC 1 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma, mce = math.min, math.max, math.ceil
local d, h1, h2, h3 = io.read("*n", "*n", "*n", "*n")

local function getcount(d, min, mid, max)
  local cnt = 0
  if max <= mid then
    local midcnt = mce((mid - max + 1) / d)
    mid = mid - midcnt * d
    cnt = cnt + midcnt
  end
  if mid <= 0 then
    return -1
  end
  if mid <= min then
    local mincnt = mce((min - mid + 1) / d)
    -- min = min - mincnt * d
    cnt = cnt + mincnt
  end
  return cnt
end

if d == 0 then
  if h1 ~= h3 and (h1 - h2) * (h2 - h3) < 0 then
    print(0)
  else
    print(-1)
  end
else
  local ret = -1
  local a = getcount(d, h1, h3, h2)
  if 0 <= a then
    if ret == -1 then ret = a else ret = mmi(ret, a) end
  end
  a = getcount(d, h3, h1, h2)
  if 0 <= a then
    if ret == -1 then ret = a else ret = mmi(ret, a) end
  end
  a = getcount(d, h2, h1, h3)
  if 0 <= a then
    if ret == -1 then ret = a else ret = mmi(ret, a) end
  end
  a = getcount(d, h2, h3, h1)
  if 0 <= a then
    if ret == -1 then ret = a else ret = mmi(ret, a) end
  end
  print(ret)
end
0