結果

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

テストケース

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

ソースコード

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())

    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