結果

問題 No.281 門松と魔法(1)
ユーザー maspy
提出日時 2020-03-03 15:59:37
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 29 ms / 1,000 ms
コード長 852 bytes
コンパイル時間 76 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-10-13 22:48:42
合計ジャッジ時間 3,242 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
D, A, B, C = map(int, read().split())


# %%
def f(A, B, C):
    """この順に降順にしたい"""
    ret = 0
    if A <= B:
        x = (B - A + D) // D
        B -= x * D
        ret += x
        if B <= 0:
            B = 0
    if B <= C:
        x = (C - B + D) // D
        C -= x * D
        ret += x
        if C <= 0:
            C = 0
    if A > B > C:
        return ret
    return -1


# %%
if D == 0:
    if (A != C) and (A < B > C or A > B < C):
        print(0)
    else:
        print(-1)
    exit()

# %%
values = [f(A, B, C) for A, B, C in [(A, C, B), (B, A, C), (B, C, A), (C, A, B)]]
values = [x for x in values if x != -1]
if values:
    print(min(values))
else:
    print(-1)
0