結果

問題 No.281 門松と魔法(1)
ユーザー kimiyuki
提出日時 2016-06-14 18:12:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-06 19:53:17
合計ジャッジ時間 3,271 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 54 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
d = int(input())
h1 = int(input())
h2 = int(input())
h3 = int(input())
def is_kadomatsu(a, b, c):
    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)
    ans = min(ans, check_count(k1,    0, k3  ))
    ans = min(ans, check_count(k1-1,  0, k3  ))
    ans = min(ans, check_count(k1  ,  0, k3-1))
    ans = min(ans, check_count(   0, k2,    0))
    ans = min(ans, check_count(   1, k2,    0))
    ans = min(ans, check_count(   0, k2,    1))
    if ans == float('inf'):
        ans = -1
print(ans)
0