結果
問題 | No.27 板の準備 |
ユーザー |
![]() |
提出日時 | 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 |
ソースコード
import itertoolsdef main():import sysV = list(map(int, sys.stdin.readline().split()))min_total = float('inf')# Generate all combinations of three distinct integers between 1 and 30for 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 boardsfor i in range(max_target + 1):if dp[i] == float('inf'):continue# Try adding each of the three boardsfor delta in (a, b, c):next_i = i + deltaif next_i <= max_target and dp[next_i] > dp[i] + 1:dp[next_i] = dp[i] + 1# Check if all target values can be achievedtotal = 0valid = Truefor v in V:if dp[v] == float('inf'):valid = Falsebreaktotal += dp[v]if valid and total < min_total:min_total = totalprint(min_total)if __name__ == "__main__":main()