結果

問題 No.281 門松と魔法(1)
ユーザー ayaoniayaoni
提出日時 2020-12-17 21:13:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 1,000 ms
コード長 1,090 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 81,784 KB
実行使用メモリ 53,572 KB
最終ジャッジ日時 2023-10-21 07:08:53
合計ジャッジ時間 4,274 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


d = I()
H1,H2,H3 = I(),I(),I()

if d == 0:
    if H1 != H2 != H3 != H1 and (max(H1,H2,H3) == H2 or min(H1,H2,H3) == H2):
        print(0)
    else:
        print(-1)
    exit()

inf = 10**18
ans = inf

m = min(H1,H3)
a = 0
if H1 == H3:
    m -= d
    a += 1
if H2 < m:
    ans = min(ans,a)
elif m > 0:
    a += (H2-m)//d+1
    ans = min(ans,a)

b = 0
if H2 > 0:
    b += max(0,(H1-H2)//d+1)
    b += max(0,(H3-H2)//d+1)
    H1 = max(0,H1-d*max(0,(H1-H2)//d+1))
    H3 = max(0,H3-d*max(0,(H3-H2)//d+1))
    if H1 == H3:
        if H1 > 0:
            ans = min(ans,b+1)
    else:
        ans = min(ans,b)

print(ans if ans != inf else -1)
0