結果

問題 No.27 板の準備
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-06 00:09:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,265 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 63,264 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 16:41:31
合計ジャッジ時間 1,403 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

int dp[35];//dp[i] := 長さiの板を作るのに、必要な最小の枚数
int main(void){
	int v[4];
	rep(i, 4) cin >> v[i];

	int ita[3], ans = 1e9;
	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] = -1;//-1は作れない
				dp[a] = 1; dp[b] = 1; dp[c] = 1;//初期化
				
				for (int x = 1; x <= 30; ++x){
					for (int y = 0; y < 3; ++y){//使う板
						if(1 <= x - ita[y] && x - ita[y] <= 30){
							if(dp[x - ita[y]] == -1)continue;//-1の時、その板は使えない
							dp[x] = min(dp[x - ita[y]] + 1, dp[x]);//y番目の板を使う
						}
					}
				}

				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]まで作れた
						// printf("%d\n", ans);
						// printf("%d %d %d\n", ita[0], ita[1], ita[2]);
						// printf("%d %d %d\n", dp[v[0]], dp[v[1]], dp[v[2]]);
					}
				}

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