結果

問題 No.27 板の準備
ユーザー masamasa
提出日時 2015-01-26 21:30:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,216 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 79,440 KB
実行使用メモリ 11,752 KB
最終ジャッジ日時 2023-08-27 03:25:02
合計ジャッジ時間 1,922 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
11,452 KB
testcase_01 AC 11 ms
11,556 KB
testcase_02 AC 10 ms
11,428 KB
testcase_03 AC 10 ms
11,432 KB
testcase_04 AC 10 ms
11,440 KB
testcase_05 AC 11 ms
11,524 KB
testcase_06 AC 10 ms
11,444 KB
testcase_07 AC 10 ms
11,752 KB
testcase_08 AC 11 ms
11,636 KB
testcase_09 AC 11 ms
11,440 KB
testcase_10 AC 11 ms
11,608 KB
testcase_11 AC 10 ms
11,552 KB
testcase_12 AC 10 ms
11,600 KB
testcase_13 AC 11 ms
11,608 KB
testcase_14 AC 11 ms
11,604 KB
testcase_15 AC 11 ms
11,620 KB
testcase_16 AC 10 ms
11,560 KB
testcase_17 AC 11 ms
11,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define V1I vector<int>
#define V2I vector< vector<int> >
#define V3I vector< vector< vector<int> > >
#define V4I vector< vector< vector< vector<int> > > >

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));

	V4I dp;
	dp.assign(31, V3I(31, V2I(31, V1I(61, INF))));

	int a, b, c, len, x;
	for (a = 1; a <= max_v; a++) {
		for (b = a; b <= max_v; b++) {
			for (c = b; c <= max_v; c++) {
				dp[a][b][c][a] = 1;
				dp[a][b][c][b] = 1;
				dp[a][b][c][c] = 1;

				for (len = a; len <= max_v; len++) {
					x =  dp[a][b][c][len];
					if (x < INF) {
						dp[a][b][c][len + a] = min(dp[a][b][c][len + a], x + 1);
						dp[a][b][c][len + b] = min(dp[a][b][c][len + b], x + 1);
						dp[a][b][c][len + c] = min(dp[a][b][c][len + c], x + 1);
					}
				}
			}
		}
	}

	int ans = INF;
	for (a = 1; a <= max_v; a++) {
		for (b = a; b <= max_v; b++) {
			for (c = b; c <= max_v; c++) {
				ans = min(ans, dp[a][b][c][v1] + dp[a][b][c][v2] + dp[a][b][c][v3] + dp[a][b][c][v4]);
			}
		}
	}

	cout << ans << endl;
	return 0;
}
0