結果

問題 No.27 板の準備
ユーザー IL_mstaIL_msta
提出日時 2015-07-16 11:31:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,657 bytes
コンパイル時間 1,005 ms
コンパイル使用メモリ 86,260 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 04:00:31
合計ジャッジ時間 1,803 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
 
#include <iostream>
#include <iomanip>
 
#include <algorithm>
#include <cmath>
 
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
 
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
 
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////

int solve(int V,int A,int B,int C){
	int ans = -1;

	if(V < A){
		return -1;
	}
	for(int a=0;a<=V/A;++a){
		for(int b=0; b<=V/B;++b){
			if( V < a*A+b*B){
				break;
			}
			for(int c=0; c<=V/C;++c){
				if( V == a*A+b*B+c*C ){
					if( ans == -1 || ans > a+b+c){
						ans = a+b+c;
					}
				}else if( V < a*A+b*B+c*C){
					break;
				}
			}
		}
	}
	return ans;
}

int main(void){
    std::cin.tie(0); 
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed;//
    //cout << setprecision(10);//
	

	int H,I,J,K;
	cin>>H>>I>>J>>K;
	int ans=-1,tans;
	for(int i=1;i<=28;++i){
		for(int j=i+1;j<=29;++j){
			for(int k=j+1;k<=30;++k){
				int dp[100];
				rep(count,31)dp[count]=1<<28;
				dp[0]=1;
				rep(count,31){
					if(dp[count] != 0){
						dp[count+i] = min( dp[count+i],dp[count]+1 );
						dp[count+j] = min( dp[count+j],dp[count]+1 );
						dp[count+k] = min( dp[count+k],dp[count]+1 );
					}
				}
				if(dp[H] != 0 && dp[I] != 0 && dp[J] != 0 && dp[K] != 0){
					tans = dp[H] + dp[I] + dp[J] + dp[K] -4 ;
					if(ans == -1 || ans > tans){
						ans = tans;
					}
				}
			}
		}
	}
	stringstream ss;
	ss << ans;
	P(ss.str());
    return 0;
}
0