結果

問題 No.281 門松と魔法(1)
ユーザー しらっ亭
提出日時 2015-09-23 22:32:39
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 880 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 22,552 KB
最終ジャッジ日時 2024-11-06 19:41:12
合計ジャッジ時間 3,357 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 1 TLE * 1 -- * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import count


def solve():
    d = int(input())

    h1 = int(input())
    h2 = int(input())
    h3 = int(input())

    ans = 0
    states = set()
    states.add((h1, h2, h3))

    while states:
        new = set()
        for h in states:
            zs = h.count(0)
            if zs >= 2:
                print(-1)
                return

            ma = max(h)
            mi = min(h)

            if h[0] != h[1] and h[0] != h[2] and h[1] != h[2] and (h[1] == ma or h[1] == mi):
                print(ans)
                return

            if h[1] > 0 and h[1] != ma:
                new.add((h[0], h[1] - d, h[2]))
            if h[0] > 0:
                new.add((h[0] - d, h[1], h[2]))
            if h[2] > 0:
                new.add((h[0], h[1], h[2] - d))
        states = new
        ans += 1

    print(-1)


if __name__ == '__main__':
    solve()
0