結果
| 問題 | No.281 門松と魔法(1) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-06-03 11:37:39 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,056 bytes |
| 記録 | |
| コンパイル時間 | 31 ms |
| コンパイル使用メモリ | 6,688 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-17 20:23:29 |
| 合計ジャッジ時間 | 1,267 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 |
ソースコード
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