結果

問題 No.27 板の準備
ユーザー masamasa
提出日時 2015-01-26 21:45:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 916 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 63,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 03:25:12
合計ジャッジ時間 1,279 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

const int INF = 1e8;

int main() {
	int v1, v2, v3, v4;
	cin >> v1 >> v2 >> v3 >> v4;
	int max_v = max(max(v1, v2), max(v3, v4));
	max_v = max(max_v, 3); //下のループを最低でも1回まわしたいため

	vector<int> dp(61, INF);

	int a, b, c, len;
	int ans = INF;
	for (a = 1; a <= max_v; a++) {
		for (b = a+1; b <= max_v; b++) {
			for (c = b+1; c <= max_v; c++) {
				fill(dp.begin(), dp.end(), INF);
				dp[a] = 1;
				dp[b] = 1;
				dp[c] = 1;

				for (len = a; len <= max_v; len++) {
					if (dp[len] < INF) {
						dp[len + a] = min(dp[len + a], dp[len] + 1);
						dp[len + b] = min(dp[len + b], dp[len] + 1);
						dp[len + c] = min(dp[len + c], dp[len] + 1);
					}
				}
				ans = min(ans, dp[v1] + dp[v2] + dp[v3] + dp[v4]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0