結果

問題 No.281 門松と魔法(1)
ユーザー pekempeypekempey
提出日時 2015-11-27 00:27:11
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 87 ms / 1,000 ms
コード長 857 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 76,808 KB
実行使用メモリ 75,784 KB
最終ジャッジ日時 2024-04-24 12:39:50
合計ジャッジ時間 7,289 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
75,404 KB
testcase_01 AC 75 ms
75,460 KB
testcase_02 AC 72 ms
75,264 KB
testcase_03 AC 75 ms
75,452 KB
testcase_04 AC 74 ms
75,644 KB
testcase_05 AC 77 ms
75,392 KB
testcase_06 AC 77 ms
75,784 KB
testcase_07 AC 73 ms
75,292 KB
testcase_08 AC 73 ms
75,648 KB
testcase_09 AC 74 ms
75,408 KB
testcase_10 AC 74 ms
75,136 KB
testcase_11 AC 73 ms
75,520 KB
testcase_12 AC 72 ms
75,392 KB
testcase_13 AC 74 ms
75,304 KB
testcase_14 AC 76 ms
75,392 KB
testcase_15 AC 75 ms
75,300 KB
testcase_16 AC 74 ms
75,648 KB
testcase_17 AC 75 ms
75,460 KB
testcase_18 AC 74 ms
75,520 KB
testcase_19 AC 74 ms
75,648 KB
testcase_20 AC 74 ms
75,648 KB
testcase_21 AC 73 ms
75,264 KB
testcase_22 AC 74 ms
75,320 KB
testcase_23 AC 74 ms
75,264 KB
testcase_24 AC 72 ms
75,392 KB
testcase_25 AC 77 ms
75,264 KB
testcase_26 AC 75 ms
75,648 KB
testcase_27 AC 74 ms
75,264 KB
testcase_28 AC 74 ms
75,264 KB
testcase_29 AC 74 ms
75,264 KB
testcase_30 AC 76 ms
75,776 KB
testcase_31 AC 73 ms
75,648 KB
testcase_32 AC 73 ms
75,412 KB
testcase_33 AC 74 ms
75,548 KB
testcase_34 AC 74 ms
75,392 KB
testcase_35 AC 72 ms
75,648 KB
testcase_36 AC 74 ms
75,776 KB
testcase_37 AC 74 ms
75,776 KB
testcase_38 AC 76 ms
75,388 KB
testcase_39 AC 74 ms
75,648 KB
testcase_40 AC 73 ms
75,556 KB
testcase_41 AC 74 ms
75,520 KB
testcase_42 AC 87 ms
75,520 KB
testcase_43 AC 74 ms
75,396 KB
testcase_44 AC 74 ms
75,520 KB
testcase_45 AC 75 ms
75,520 KB
testcase_46 AC 74 ms
75,520 KB
testcase_47 AC 74 ms
75,440 KB
testcase_48 AC 74 ms
75,552 KB
testcase_49 AC 75 ms
75,392 KB
testcase_50 AC 74 ms
75,688 KB
testcase_51 AC 76 ms
75,264 KB
testcase_52 AC 74 ms
75,136 KB
testcase_53 AC 74 ms
75,288 KB
testcase_54 AC 75 ms
75,296 KB
testcase_55 AC 76 ms
75,392 KB
testcase_56 AC 75 ms
75,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

INF = 10 ** 18

d, h1, h2, h3 = [input() for _ in xrange(4)]

def is_kadomatsu(a, b, c):
	return a != c and (a < b and b > c or a > b and b < c)

if is_kadomatsu(h1, h2, h3):
	print 0
	sys.exit()

if d == 0:
	print -1
	sys.exit()

f = lambda x: max(0, x - d)

ans = 0
if h1 == h3:
	h1 = f(h1)
	ans += 1

if h1 == h3:
	print -1
	sys.exit()

# h1 < h3 and h3 > h2
ans1 = ans
t1, t2, t3 = h1, h2, h3

k1 = max(0, (t1 - t2 + d) / d)
k3 = max(0, (t3 - t2 + d) / d)

t1 = max(0, t1 - k1 * d)
t3 = max(0, t3 - k3 * d)
ans1 = ans + k1 + k3
if t1 == t3:
	t1 = f(t1)
	ans1 += 1

if not is_kadomatsu(t1, t2, t3):
	ans1 = INF

# h1 > h3 and h3 < h2
t1, t2, t3 = h1, h2, h3
k2 = max(0, (t2 - min(t1, t3) + d) / d)
ans2 = ans + k2

t2 = max(0, t2 - k2 * d)
if not is_kadomatsu(t1, t2, t3):
	ans2 = INF

ans = min(ans1, ans2)
if ans == INF: ans = -1
print ans
0