結果

問題 No.27 板の準備
ユーザー NotationNapNotationNap
提出日時 2015-04-28 06:17:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 837 bytes
コンパイル時間 1,364 ms
コンパイル使用メモリ 146,412 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 14:02:56
合計ジャッジ時間 2,123 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long Int;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i))

int dfs(int n, int B[3], int d, int s) {
	if (n == 0) return d;
	if (n < 0) return 999999;
	int res = 999999;
	if (s <= 0) res = min(res, dfs(n - B[0], B, d + 1, 0));
	if (s <= 1) res = min(res, dfs(n - B[1], B, d + 1, 1));
	if (s <= 2) res = min(res, dfs(n - B[2], B, d + 1, 2));
	return res;
}

int check(int a[4], int B[3]) {
	int res = 0;
	REP(i, 4) res += dfs(a[i], B, 0, 0);
	return res;
}

int a[4];
int main() {
	REP(i, 4) cin >> a[i];
	sort(a, a + 4);
	int best = 999999;
	for (int A = 1; A <= a[0]; A++) {
		for (int B = A + 1; B <= a[3]; B++) {
			for (int C = B + 1; C <= a[3]; C++) {
				int bs[] = { A, B, C };
				int x = check(a, bs);
				if (best > x) best = x;
			}
		}
	}
	cout << best << endl;
}
0