結果
| 問題 |
No.27 板の準備
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 18:49:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 5,000 ms |
| コード長 | 1,122 bytes |
| コンパイル時間 | 179 ms |
| コンパイル使用メモリ | 82,724 KB |
| 実行使用メモリ | 77,300 KB |
| 最終ジャッジ日時 | 2025-03-20 18:51:46 |
| 合計ジャッジ時間 | 2,609 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
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()
lam6er