結果

問題 No.281 門松と魔法(1)
ユーザー rpy3cpprpy3cpp
提出日時 2015-09-18 23:20:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,803 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 8,204 KB
最終ジャッジ日時 2023-08-06 16:23:17
合計ジャッジ時間 3,229 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,076 KB
testcase_01 AC 16 ms
8,012 KB
testcase_02 AC 17 ms
8,168 KB
testcase_03 AC 16 ms
8,100 KB
testcase_04 AC 16 ms
8,116 KB
testcase_05 AC 16 ms
8,016 KB
testcase_06 AC 17 ms
8,048 KB
testcase_07 AC 17 ms
8,016 KB
testcase_08 AC 16 ms
8,064 KB
testcase_09 AC 17 ms
8,016 KB
testcase_10 AC 16 ms
8,100 KB
testcase_11 AC 17 ms
8,112 KB
testcase_12 AC 17 ms
8,112 KB
testcase_13 AC 16 ms
8,060 KB
testcase_14 AC 18 ms
8,008 KB
testcase_15 AC 17 ms
8,012 KB
testcase_16 AC 16 ms
8,040 KB
testcase_17 AC 16 ms
8,148 KB
testcase_18 AC 17 ms
8,060 KB
testcase_19 AC 17 ms
8,040 KB
testcase_20 AC 16 ms
8,072 KB
testcase_21 AC 16 ms
8,100 KB
testcase_22 AC 17 ms
8,048 KB
testcase_23 AC 17 ms
8,100 KB
testcase_24 AC 16 ms
7,960 KB
testcase_25 AC 17 ms
8,068 KB
testcase_26 AC 16 ms
8,048 KB
testcase_27 AC 17 ms
8,064 KB
testcase_28 AC 17 ms
8,068 KB
testcase_29 AC 16 ms
8,060 KB
testcase_30 AC 16 ms
8,136 KB
testcase_31 AC 17 ms
8,016 KB
testcase_32 AC 16 ms
8,104 KB
testcase_33 AC 16 ms
8,076 KB
testcase_34 AC 16 ms
8,024 KB
testcase_35 AC 16 ms
8,048 KB
testcase_36 AC 16 ms
8,064 KB
testcase_37 AC 16 ms
8,068 KB
testcase_38 AC 17 ms
8,116 KB
testcase_39 AC 17 ms
8,048 KB
testcase_40 AC 17 ms
8,060 KB
testcase_41 AC 17 ms
8,008 KB
testcase_42 AC 16 ms
8,112 KB
testcase_43 AC 16 ms
7,964 KB
testcase_44 WA -
testcase_45 AC 16 ms
8,016 KB
testcase_46 AC 16 ms
8,016 KB
testcase_47 AC 16 ms
7,964 KB
testcase_48 AC 16 ms
8,112 KB
testcase_49 AC 16 ms
7,984 KB
testcase_50 AC 16 ms
8,100 KB
testcase_51 AC 16 ms
8,020 KB
testcase_52 AC 16 ms
8,012 KB
testcase_53 AC 16 ms
8,016 KB
testcase_54 AC 16 ms
8,112 KB
testcase_55 AC 16 ms
8,004 KB
testcase_56 AC 16 ms
8,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(d, h1, h2, h3):
    if h1 == h2 == h3:
        if max(0, h1 - d) == max(0, h1 - 2*d):
            return -1
        return 3
    if d == 0:
        if h1 == h2 or h2 == h3 or h3 == h1:
            return -1
        if max(h1, h2, h3) == h2 or min(h1, h2, h3) == h2:
            return 0
        else:
            return -1 
    if h1 == h3:
        if h1 == 0:
            return -1
        if h2 > h1:
            return 1
        # h2 < h1
        if h1 - d > h2:
            return 1
        if max(0, h1 - d) == h2:
            if h2 > 0:
                return 2
            else:
                return -1
        if max(0, h1 - d) == max(0, h2 - d):
            return -1
        return 2
    if h1 > h3:
        h1, h3 = h3, h1
    # h1 < h3 に強制的に変更
    if h1 > h2:
        return 0
    if h3 < h2:
        return 0
    if h1 == h2:
        if h2 > 0:
            return 1
        else:
            return 0
    if h3 == h2:
        if max(0, h2 - d) < h1:
            return 1
        if max(0, h3 - d) != h1:
            return 1
        if max(0, h3 - d * 2) != h1:
            return 2
        if max(0, h3 - d) != max(0, h1 - d):
            return 2
        if max(0, h2 - d * 2) < h1:
            return 2
        return -1
    # h1 < h2 < h3 のケース
    s3 = (h3 - h2) // d + 1
    h33 = max(0, h3 - s3 * d)
    if h33 == h1:
        if h1 > 0:
            s3 += 1
        else:
            s3 = float('inf')
    s2 = (h2 - h1) // d + 1
    h22 = max(0, h2 - s2 * d)
    if h22 == h1:
        if h1 > 0:
            s2 += 1
        else:
            s2 = float('inf')
    s = min(s3, s2)
    if s == float('inf'):
        return -1
    else:
        return s

d = int(input())
h1 = int(input())
h2 = int(input())
h3 = int(input())
print(solve(d, h1, h2, h3))
0