結果

問題 No.27 板の準備
ユーザー pekempeypekempey
提出日時 2015-08-19 16:22:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 932 bytes
コンパイル時間 1,208 ms
コンパイル使用メモリ 144,136 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 04:07:07
合計ジャッジ時間 2,212 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 7;

ll dp[4][41];
int a[3];

void calc() {
	rep (i, 4) rep (j, 41) dp[i][j] = inf;
	dp[0][0] = 0;
	rep2 (i, 1, 4) {
		rep (j, 41) {
			if (j - a[i - 1] < 0) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i - 1]] + 1);
			}
		}
	}
}

int main() {
	int v0, v1, v2, v3;
	cin >> v0 >> v1 >> v2 >> v3;

	ll ans = inf;

	rep2 (i, 1, 31) {
		rep2 (j, i + 1, 31) {
			rep2 (k, j + 1, 31) {
				a[0] = i;
				a[1] = j;
				a[2] = k;
				calc();

				ll x = dp[3][v0] + dp[3][v1] + dp[3][v2] + dp[3][v3];
				ans = min(ans, x);
			}
		}
	}

	cout << ans << endl;

	return 0;
}
0