結果

問題 No.27 板の準備
ユーザー furonfuron
提出日時 2023-06-01 16:39:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,584 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 127,308 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 02:05:39
合計ジャッジ時間 2,516 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <bitset>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_map>
#include <random>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;
const int inf = (1 << 30) - 1;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
const int MOD = 998244353;

vi gettbl(int a, int b, int c) {
	vvi dp(4, vi(31, inf));
	vi l = { a,b,c };
	
	dp[0][0] = 0;
	for (int i = 1; i <= 3; i++) {
		for (int j = 0; j <= 30; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j >= l[i - 1]) dp[i][j] = min(dp[i][j], dp[i][j - l[i - 1]] + 1);
		}
	}
	
	return dp[3];
}

int main() {
	vi v(4);
	for (int i = 0; i < 4; i++) {
		cin >> v[i];
	}
	
	int ans = inf;
	for (int i = 1; i <= 28; i++) {
		for (int j = i + 1; j <= 29; j++) {
			for (int k = j + 1; k <= 30; k++) {
				vi tbl = gettbl(i, j, k);
				int cnt = 0;
				bool ok = true;
				for (int l = 0; l < 4; l++) {
					if (tbl[v[l]] == inf) {
						ok = false;
						break;
					}
					cnt += tbl[v[l]];
				}

				if (ok) {
					ans = min(ans, cnt);
				}
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}
0