結果

問題 No.281 門松と魔法(1)
コンテスト
ユーザー norioc
提出日時 2025-11-09 03:14:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 720 bytes
コンパイル時間 3,149 ms
コンパイル使用メモリ 82,648 KB
実行使用メモリ 67,476 KB
最終ジャッジ日時 2025-11-09 03:14:54
合計ジャッジ時間 5,503 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 WA * 25 RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

def ceildiv(a: int, b: int) -> int:
    return (a + b - 1) // b


INF = 1 << 60
D = int(input())
H1 = int(input())
H2 = int(input())
H3 = int(input())


# a > b > c にするのに必要な操作回数
def f(a, b, c):
    res = 0
    if a <= b:
        x = ceildiv(b-a, D) + 1
        res += x
        b = max(0, b - x * D)

    if b == 0: return -1

    if b <= c:
        x = ceildiv(c-b, D) + 1
        res += x
        c = max(0, c - x * D)

    return res


ans = INF
# 真ん中が一番低い、または一番高い
for a, b, c in [(H2, H1, H3), (H2, H3, H1), (H1, H3, H2), (H3, H1, H2)]:
    res = f(a, b, c)
    if res == -1: continue
    ans = min(ans, res)

if ans == INF:
    print(-1)
else:
    print(ans)
0