結果

問題 No.281 門松と魔法(1)
ユーザー ayaoni
提出日時 2020-12-17 21:13:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 1,000 ms
コード長 1,090 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 81,948 KB
実行使用メモリ 54,408 KB
最終ジャッジ日時 2024-09-21 08:16:53
合計ジャッジ時間 3,817 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


d = I()
H1,H2,H3 = I(),I(),I()

if d == 0:
    if H1 != H2 != H3 != H1 and (max(H1,H2,H3) == H2 or min(H1,H2,H3) == H2):
        print(0)
    else:
        print(-1)
    exit()

inf = 10**18
ans = inf

m = min(H1,H3)
a = 0
if H1 == H3:
    m -= d
    a += 1
if H2 < m:
    ans = min(ans,a)
elif m > 0:
    a += (H2-m)//d+1
    ans = min(ans,a)

b = 0
if H2 > 0:
    b += max(0,(H1-H2)//d+1)
    b += max(0,(H3-H2)//d+1)
    H1 = max(0,H1-d*max(0,(H1-H2)//d+1))
    H3 = max(0,H3-d*max(0,(H3-H2)//d+1))
    if H1 == H3:
        if H1 > 0:
            ans = min(ans,b+1)
    else:
        ans = min(ans,b)

print(ans if ans != inf else -1)
0