結果

問題 No.27 板の準備
ユーザー ciel
提出日時 2015-07-14 16:33:50
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 497 bytes
コンパイル時間 674 ms
コンパイル使用メモリ 36,608 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-26 10:34:50
合計ジャッジ時間 1,290 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         for(int i=0;i<4;i++)scanf("%d",&V[i]),T+=V[i];
      |                             ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <vector>
#include <cstdio>
int main(){
	std::vector<int>V(4),X(3);
	int T=0,R;
	for(int i=0;i<4;i++)scanf("%d",&V[i]),T+=V[i];
	R=T;
	for(X[0]=1;X[0]<=30;X[0]++)for(X[1]=X[0]+1;X[1]<=30;X[1]++)for(X[2]=X[1]+1;X[2]<=30;X[2]++){
		std::vector<int>bag(T+1);
		bag[0]=1;
		for(int i=0;i<3;i++)for(int j=X[i];j<=T;j++)if(bag[j-X[i]]&&(!bag[j]||bag[j]>bag[j-X[i]]))bag[j]=bag[j-X[i]]+1;
		int i=0,r=0;
		for(;i<4;r+=bag[V[i++]]-1)if(!bag[V[i]])break;
		if(i==4&&R>r)R=r;
	}
	printf("%d\n",R);
}
0