結果

問題 No.281 門松と魔法(1)
ユーザー kimiyukikimiyuki
提出日時 2016-06-14 18:14:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 37 ms / 1,000 ms
コード長 1,175 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-24 12:42:04
合計ジャッジ時間 3,360 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#!/usr/bin/env python3
d = int(input())
h1 = int(input())
h2 = int(input())
h3 = int(input())
def is_kadomatsu(a, b, c):
    assert a >= 0 and b >= 0 and c >= 0
    return a != c and ((a < b and b > c) or (a > b and b < c))
def make_lt(a, b):
    if b == 0:
        return float('inf')
    else:
        return max(0, (a - (b-1) + d-1) // d)
def check_count(k1, k2, k3):
    if k1 < 0 or k2 < 0 or k3 < 0:
        return float('inf')
    g1 = max(0, h1 - k1 * d)
    g2 = max(0, h2 - k2 * d)
    g3 = max(0, h3 - k3 * d)
    if is_kadomatsu(g1, g2, g3):
        return k1 + k2 + k3
    else:
        return float('inf')
if d == 0:
    if is_kadomatsu(h1, h2, h3):
        ans = 0
    else:
        ans = -1
else:
    ans = float('inf')
    k1 = make_lt(h1, h2)
    k2 = make_lt(h2, min(h1, h3))
    k3 = make_lt(h3, h2)
    for i1 in range(-3,3+1):
        for i2 in range(-3,3+1):
            for i3 in range(-3,3+1):
                for l1 in [0, k1]:
                    for l2 in [0, k2]:
                        for l3 in [0, k3]:
                            ans = min(ans, check_count(l1 + i1, l2 + i2, l3 + i3))
    if ans == float('inf'):
        ans = -1
print(ans)
0