結果

問題 No.281 門松と魔法(1)
コンテスト
ユーザー roiti46
提出日時 2015-09-18 22:55:47
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 82 ms / 1,000 ms
コード長 894 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 174 ms
コンパイル使用メモリ 77,488 KB
最終ジャッジ日時 2025-12-03 16:59:17
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

d = int(raw_input())
_H1, _H2, _H3 = int(raw_input()), int(raw_input()), int(raw_input())

if d == 0:
    if _H1 != _H3 and (_H1 < _H2 > _H3 or _H1 > _H2 < _H3):
        print 0
    else:
        print -1
    exit()

ans = -1
a1 = a2 = 0
H1, H2, H3 = _H1, _H2, _H3
if H1 >= H2:
    c = (H1 - H2 + d) / d
    H1 = max(0, H1 - d * c)
    a1 += c
if H3 >= H2:
    c = (H3 - H2 + d) / d
    H3 = max(0, H3 - d * c)
    a1 += c
if H1 == H3:
    H1 = max(0, H1 - d)
    a1 += 1
if H1 != H3 and H1 < H2 > H3:
    ans = a1

H1, H2, H3 = _H1, _H2, _H3
if H1 <= H2:
    c = (H2 - H1 + d) / d
    H2 = max(0, H2 - d * c)
    a2 += c
if H3 <= H2:
    c = (H2 - H3 + d) / d
    H2 = max(0, H2- d * c)
    a2 += c
if H1 == H3:
    H1 = max(0, H1 - d)
    a2 += 1
if H1 == H2:
    H2 = max(0, H2 - d)
    a2 += 1
if H1 != H3 and H1 > H2 < H3:
    if ans == -1: ans = a2
    else: ans = min(ans, a2)
print ans
0