結果

問題 No.281 門松と魔法(1)
ユーザー しらっ亭しらっ亭
提出日時 2015-09-23 23:15:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,332 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-24 11:53:41
合計ジャッジ時間 2,828 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import heapq


def next_to(mu, mi, h, d):
    if mu < h:
        t = mu
    elif mi < h:
        t = mi
    else:
        return 1
    return (h - t) // d + 1


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

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

    if d == 0:
        if h1 != h2 and h1 != h3 and h2 != h3 and (h2 == max(h1, h2, h3) or h2 == min(h1, h2, h3)):
            print(0)
        else:
            print(-1)
        return

    q = [(0, (h1, h2, h3))]

    while q:
        n, h = heapq.heappop(q)

        zs = h.count(0)
        if zs >= 2:
            continue

        ma = max(h)
        mi = min(h)
        mu = sum(h) - ma - mi
        mic = h.count(mi)

        if h[0] != h[1] and h[0] != h[2] and h[1] != h[2] and h[1] != mu:
            print(n)
            return

        if h[0] != mi or mic != 1:
            m = next_to(mu, mi, h[0], d)
            heapq.heappush(q, (n + m, (max(0, h[0] - d * m), h[1], h[2])))

        if (h[1] != mi or mic != 1) and h[1] != ma:
            m = next_to(mu, mi, h[1], d)
            heapq.heappush(q, (n + m, (h[0], max(0, h[1] - d * m), h[2])))

        if h[2] != mi or mic != 1:
            m = next_to(mu, mi, h[2], d)
            heapq.heappush(q, (n + m, (h[0], h[1], max(0, h[2] - d * m))))

    print(-1)


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