結果

問題 No.27 板の準備
ユーザー ゴリポン先生ゴリポン先生
提出日時 2024-02-21 15:07:05
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 761 bytes
コンパイル時間 5,310 ms
コンパイル使用メモリ 168,664 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-21 15:07:12
合計ジャッジ時間 6,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 4 ms
6,676 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 5 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 4 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

module main;

import std;

void chMin(T)(ref T a, in T b)
{
	if (a > b) a = b;
}

void main()
{
	immutable INF = int.max / 3;
	auto V = readln.split.to!(int[]);
	V.sort;
	int ans = INF;
	foreach (A; 1 .. 29) {
		foreach (B; A + 1 .. 30) {
LOOP:
			foreach (C; B + 1 .. 31) {
				int cnt = 0;
				foreach (v; V) {
					auto dp = new int[](31);
					dp[] = INF;
					dp[0] = 0;
					foreach (i; 1 .. v + 1) {
						if (i - A >= 0 && dp[i - A] != INF)
							chMin(dp[i], dp[i - A] + 1);
						if (i - B >= 0 && dp[i - B] != INF)
							chMin(dp[i], dp[i - B] + 1);
						if (i - C >= 0 && dp[i - C] != INF)
							chMin(dp[i], dp[i - C] + 1);
					}
					if (dp[v] == INF) continue LOOP;
					cnt += dp[v];
				}
				chMin(ans, cnt);
			}
		}
	}
	writeln(ans);
}
0