結果

問題 No.281 門松と魔法(1)
ユーザー ckawatakckawatak
提出日時 2019-02-11 17:28:42
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,258 bytes
コンパイル時間 1,560 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 75,692 KB
最終ジャッジ日時 2023-09-25 19:09:50
合計ジャッジ時間 11,242 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,436 KB
testcase_01 AC 72 ms
71,512 KB
testcase_02 AC 72 ms
71,400 KB
testcase_03 AC 72 ms
71,156 KB
testcase_04 AC 71 ms
71,336 KB
testcase_05 AC 72 ms
71,240 KB
testcase_06 AC 79 ms
71,332 KB
testcase_07 AC 75 ms
71,448 KB
testcase_08 AC 74 ms
71,336 KB
testcase_09 AC 75 ms
71,520 KB
testcase_10 AC 73 ms
71,208 KB
testcase_11 AC 75 ms
71,596 KB
testcase_12 AC 74 ms
71,240 KB
testcase_13 AC 73 ms
71,596 KB
testcase_14 AC 75 ms
71,244 KB
testcase_15 AC 85 ms
75,380 KB
testcase_16 AC 73 ms
71,260 KB
testcase_17 AC 103 ms
75,692 KB
testcase_18 AC 71 ms
71,332 KB
testcase_19 AC 104 ms
75,264 KB
testcase_20 AC 83 ms
75,496 KB
testcase_21 AC 75 ms
75,356 KB
testcase_22 AC 72 ms
71,544 KB
testcase_23 AC 76 ms
75,324 KB
testcase_24 AC 73 ms
71,384 KB
testcase_25 AC 74 ms
71,332 KB
testcase_26 AC 72 ms
71,308 KB
testcase_27 AC 72 ms
71,300 KB
testcase_28 AC 72 ms
71,340 KB
testcase_29 AC 73 ms
71,176 KB
testcase_30 AC 74 ms
71,640 KB
testcase_31 AC 73 ms
71,528 KB
testcase_32 AC 73 ms
71,392 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 71 ms
71,136 KB
testcase_36 AC 73 ms
71,516 KB
testcase_37 AC 75 ms
71,336 KB
testcase_38 WA -
testcase_39 AC 71 ms
71,164 KB
testcase_40 AC 74 ms
71,332 KB
testcase_41 AC 74 ms
71,352 KB
testcase_42 AC 75 ms
71,240 KB
testcase_43 AC 72 ms
71,356 KB
testcase_44 AC 73 ms
71,392 KB
testcase_45 AC 74 ms
71,424 KB
testcase_46 AC 74 ms
71,368 KB
testcase_47 AC 76 ms
71,360 KB
testcase_48 AC 73 ms
71,592 KB
testcase_49 AC 73 ms
71,468 KB
testcase_50 AC 76 ms
71,504 KB
testcase_51 AC 72 ms
71,156 KB
testcase_52 AC 72 ms
71,336 KB
testcase_53 AC 71 ms
71,244 KB
testcase_54 AC 71 ms
71,528 KB
testcase_55 AC 72 ms
71,332 KB
testcase_56 AC 73 ms
71,312 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 magic_until(h,t):
    i = 0
    while t <= h:
        if t == 0 and h == 0:
            return 0,float('inf')
        h = magic(h)
        i = i + 1
    return h,i

def recheck(h1, h2, h3):
    if is_kadomatsu(h1,h2,h3):
        return True,0
    else:
        m = max(h1,h3)
        n = min(h1,h3)
        h4,i = magic_until(m,h2)
        h5,j = magic_until(h2,n)
        if i < j:
            return is_kadomatsu(h4 if h1 == m else h1, h2, h4 if h3 == m else h3),i
        else:
            return is_kadomatsu(h1, h5, h3),j

def check(h1, h2, h3):
    if D == 0:
        return is_kadomatsu(h1, h2, h3),0
    elif h1 == h2 and h2 == h3 and h1 == h3:
        h1 = magic(magic(h1))
        h3 = magic(h3)
        return is_kadomatsu(h1,h2,h3),3

    elif h1 == h3 and h1 != h2 and h3 != h2:
        h1 = magic(h1)
        if is_kadomatsu(h1,h2,h3):
            return True,1
        else:
            return recheck(h1,h2,h3)
    else:
        return recheck(h1,h2,h3)

found,i = check(H1,H2,H3)
if found:
    print(i)
else:
    print(-1)
0