結果
| 問題 |
No.27 板の準備
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-07-16 11:31:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,657 bytes |
| コンパイル時間 | 1,136 ms |
| コンパイル使用メモリ | 87,268 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-26 11:37:14 |
| 合計ジャッジ時間 | 1,805 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#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;
}
IL_msta