結果

問題 No.281 門松と魔法(1)
ユーザー yuppe19 😺
提出日時 2015-12-26 19:09:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,066 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-11-06 19:49:21
合計ジャッジ時間 3,749 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 56 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# †
inf = int(1e9) + 100

def bye(s):
    print(s)
    exit(0)

def ok(x, y, z):
    ok1 = x > y and y < z
    ok2 = x < y and y > z
    return x!=z and (ok1 or ok2)

def count(my, your, d):
    if your==0:
        return inf
    if my < your:
        return 0
    return (my - your + d) // d

def cut(my, d, times):
    return max(0, my-d*times)

d  = int(input())
h1 = int(input())
h2 = int(input())
h3 = int(input())
assert 0 <= d  <= int(1e9)
assert 0 <= h1 <= int(1e9)
assert 0 <= h2 <= int(1e9)
assert 0 <= h3 <= int(1e9)

if ok(h1, h2, h3):
    bye('0')
if d==0:
    bye('-1')

r1 = 0
x, y, z = h1, h2, h3
if x==z:
    x = cut(x, d, 1)
    r1 += 1
p = count(x, y, d)
r1 += p
x = cut(x, d, p)
q = count(z, y, d)
r1 += q
z = cut(z, d, q)
if not ok(x, y, z):
    r1 = inf

r2 = 0
x, y, z = h1, h2, h3
if x==z:
    x = cut(x, d, 1)
    r2 += 1
p = count(y, x, d)
r2 += p
y = cut(y, d, p)
q = count(y, z, d)
r2 += q
cut(y, d, q)
if not ok(x, y, z):
    r2 = inf
res = min(r1, r2)
if res >= inf:
    res = -1
print(res)
0