結果

問題 No.27 板の準備
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-07 14:11:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 935 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 53,048 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 04:32:11
合計ジャッジ時間 1,253 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e6;
int dp[35];//dp[i] := 長さiの板を作るのに、必要な最小の枚数

int main(void){
	int v[4];
	rep(i, 4) cin >> v[i];

	int ita[3], ans = INF;
	for (int a = 1; a <= 30; ++a){//a,b,cを全探索
		for (int b = a + 1; b <= 30; ++b){
			for (int c = b + 1; c <= 30; ++c){

				ita[0] = a; ita[1] = b; ita[2] = c;
				rep(i, 35)dp[i] = INF;//-1は作れない
				dp[a] = 1; dp[b] = 1; dp[c] = 1;//初期化

				for (int y = 0; y < 3; ++y){//使う板
					for (int x = 1; x <= 30; ++x){
						if(x - ita[y] > 0){
							dp[x] = min(dp[x], dp[x - ita[y]] + 1);
						}
					}
				}

				int now = 0;
				rep(i, 4){
					if(dp[v[i]] != -1){
						now += dp[v[i]];
					}else{
						break;
					}
					if(i == 3){
						ans = min(now, ans);//v[0]~v[3]まで作れた
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0