結果

問題 No.281 門松と魔法(1)
ユーザー ckawatakckawatak
提出日時 2019-02-16 14:31:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 1,000 ms
コード長 978 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 81,840 KB
実行使用メモリ 53,564 KB
最終ジャッジ日時 2023-10-22 04:19:48
合計ジャッジ時間 4,051 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,564 KB
testcase_01 AC 36 ms
53,564 KB
testcase_02 AC 34 ms
53,564 KB
testcase_03 AC 35 ms
53,564 KB
testcase_04 AC 35 ms
53,564 KB
testcase_05 AC 35 ms
53,564 KB
testcase_06 AC 36 ms
53,564 KB
testcase_07 AC 34 ms
53,564 KB
testcase_08 AC 35 ms
53,564 KB
testcase_09 AC 36 ms
53,564 KB
testcase_10 AC 36 ms
53,564 KB
testcase_11 AC 40 ms
53,564 KB
testcase_12 AC 34 ms
53,564 KB
testcase_13 AC 36 ms
53,564 KB
testcase_14 AC 35 ms
53,564 KB
testcase_15 AC 36 ms
53,564 KB
testcase_16 AC 36 ms
53,564 KB
testcase_17 AC 36 ms
53,564 KB
testcase_18 AC 35 ms
53,564 KB
testcase_19 AC 35 ms
53,564 KB
testcase_20 AC 36 ms
53,564 KB
testcase_21 AC 35 ms
53,564 KB
testcase_22 AC 36 ms
53,564 KB
testcase_23 AC 35 ms
53,564 KB
testcase_24 AC 36 ms
53,564 KB
testcase_25 AC 36 ms
53,564 KB
testcase_26 AC 36 ms
53,564 KB
testcase_27 AC 35 ms
53,564 KB
testcase_28 AC 36 ms
53,564 KB
testcase_29 AC 34 ms
53,564 KB
testcase_30 AC 35 ms
53,564 KB
testcase_31 AC 37 ms
53,564 KB
testcase_32 AC 37 ms
53,564 KB
testcase_33 AC 37 ms
53,564 KB
testcase_34 AC 35 ms
53,564 KB
testcase_35 AC 37 ms
53,564 KB
testcase_36 AC 38 ms
53,564 KB
testcase_37 AC 37 ms
53,564 KB
testcase_38 AC 35 ms
53,564 KB
testcase_39 AC 35 ms
53,564 KB
testcase_40 AC 36 ms
53,564 KB
testcase_41 AC 36 ms
53,564 KB
testcase_42 AC 35 ms
53,564 KB
testcase_43 AC 35 ms
53,564 KB
testcase_44 AC 34 ms
53,564 KB
testcase_45 AC 34 ms
53,564 KB
testcase_46 AC 37 ms
53,564 KB
testcase_47 AC 36 ms
53,564 KB
testcase_48 AC 35 ms
53,564 KB
testcase_49 AC 36 ms
53,564 KB
testcase_50 AC 36 ms
53,564 KB
testcase_51 AC 34 ms
53,564 KB
testcase_52 AC 35 ms
53,564 KB
testcase_53 AC 35 ms
53,564 KB
testcase_54 AC 35 ms
53,564 KB
testcase_55 AC 34 ms
53,564 KB
testcase_56 AC 35 ms
53,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def is_kadomatsu(h1, h2, h3):
    return h1 != h3 and ((h1 < h2 and h3 < h2) or (h2 < h1 and h2 < h3))

def magic(h):
    return max(0, h-D)

def solve():
    if D == 0:
        return 0 if is_kadomatsu(H1,H2,H3) else -1

    result = float('inf')
    
    # maximize h2
    h1 = H1
    h2 = H2
    h3 = H3
    x = max(0, (h1-h2+D)//D)
    y = max(0, (h3-h2+D)//D)
    h1 = max(0, h1-x*D)
    h3 = max(0, h3-y*D)
    if h1 == h3 and h1 != 0:
        h1 = magic(h1)
        x = x + 1
    if is_kadomatsu(h1,h2,h3):
        result = min(result, x+y)

    # minimize h2
    h1 = H1
    h2 = H2
    h3 = H3
    x = 0
    if h1 == h3:
        h1 = magic(h1)
        x = x + 1
    shorter = min(h1,h3)
    y = max(0, (h2-shorter+D)//D)
    h2 = max(0, h2-y*D)
    if is_kadomatsu(h1,h2,h3):
        result = min(result, x+y)

    if result == float('inf'):
        result = -1

    return result

print(solve())
0