結果

問題 No.27 板の準備
ユーザー dangodango
提出日時 2023-07-09 15:44:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 438 ms / 5,000 ms
コード長 940 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 84,716 KB
最終ジャッジ日時 2023-09-30 19:04:40
合計ジャッジ時間 6,904 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
79,816 KB
testcase_01 AC 182 ms
80,044 KB
testcase_02 AC 438 ms
83,680 KB
testcase_03 AC 199 ms
81,252 KB
testcase_04 AC 291 ms
83,476 KB
testcase_05 AC 281 ms
84,352 KB
testcase_06 AC 312 ms
84,660 KB
testcase_07 AC 323 ms
83,548 KB
testcase_08 AC 342 ms
83,876 KB
testcase_09 AC 329 ms
83,708 KB
testcase_10 AC 315 ms
83,632 KB
testcase_11 AC 296 ms
83,448 KB
testcase_12 AC 313 ms
84,716 KB
testcase_13 AC 292 ms
83,460 KB
testcase_14 AC 290 ms
83,280 KB
testcase_15 AC 324 ms
83,760 KB
testcase_16 AC 239 ms
82,268 KB
testcase_17 AC 338 ms
83,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import List

def main():
    vi = list(map(int, input().split()))
    vi.sort()
    maxV = vi[-1]

    r = float('inf')
    for a in range(1, maxV + 1):
        for b in range(a, maxV + 1):
            for c in range(b, maxV + 1):
                d = calc(vi, [a, b, c])
                if d > 0:
                    r = min(r, d)

    print(r)

def calc(vi: List[int], ai: List[int]) -> int:
    dp = [-1] * (vi[-1] + 1)
    dp[0] = 0

    def updateDp(dp: List[int], i: int, a: int) -> int:
        if i >= a and dp[i - a] >= 0:
            return dp[i - a] + 1
        else:
            return -1

    for i in range(1, len(dp)):
        a = [updateDp(dp, i, a) for a in ai]
        a = list(filter(lambda x: x >= 0, a))
        if len(a) > 0:
            dp[i] = min(a)

    ci = [dp[v] for v in vi]
    if all([a >= 0 for a in ci]):
        return sum(ci)
    else:
        return -1

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