結果

問題 No.281 門松と魔法(1)
ユーザー mban
提出日時 2017-07-26 08:21:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 870 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 67,264 KB
最終ジャッジ日時 2024-10-09 17:34:40
合計ジャッジ時間 4,222 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 37 WA * 11 RE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

d = int(input())
H1 = int(input())
H2 = int(input())
H3 = int(input())

impossible = 9999999999

ans = impossible


def A(a, b, c):
    result = 0
    if a == c:
        if a <= d:
            return impossible
        else:
            a = max(0, a - d)
            result += 1
    m = min(a, c)

    if b >= m:
        sa = b - m
        bb = sa // d + 1
        result += bb
    return result


def B(a, b, c):
    result = 0
    if b == 0:
        return impossible
    if a >= b:
        sa = a - b
        aa = sa // d + 1
        result += aa
        a = max(0, a - aa * d)
    if c >= b:
        sa = c - b
        cc = sa // d + 1
        result += cc
        c = max(0, c - cc * d)
    if a == c:
        if a == 0:
            return impossible
        result +=1
    return  result

ans = min(A(H1,H2,H3),B(H1,H2,H3))

print(-1 if ans == impossible else ans)
0