結果

問題 No.27 板の準備
ユーザー lam6er
提出日時 2025-03-20 18:49:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 1,122 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 82,348 KB
実行使用メモリ 77,272 KB
最終ジャッジ日時 2025-03-20 18:51:47
合計ジャッジ時間 2,760 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

def main():
    import sys
    V = list(map(int, sys.stdin.readline().split()))
    min_total = float('inf')
    # Generate all combinations of three distinct integers between 1 and 30
    for a, b, c in itertools.combinations(range(1, 31), 3):
        max_target = max(V)
        dp = [float('inf')] * (max_target + 1)
        dp[0] = 0  # Base case: 0 length requires 0 boards
        
        for i in range(max_target + 1):
            if dp[i] == float('inf'):
                continue
            # Try adding each of the three boards
            for delta in (a, b, c):
                next_i = i + delta
                if next_i <= max_target and dp[next_i] > dp[i] + 1:
                    dp[next_i] = dp[i] + 1
        
        # Check if all target values can be achieved
        total = 0
        valid = True
        for v in V:
            if dp[v] == float('inf'):
                valid = False
                break
            total += dp[v]
        
        if valid and total < min_total:
            min_total = total
    
    print(min_total)

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