結果

問題 No.50 おもちゃ箱
ユーザー btkbtk
提出日時 2015-05-22 12:31:54
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 967 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 67,728 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-30 21:34:21
合計ジャッジ時間 3,447 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 8 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 6 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 7 ms
4,384 KB
testcase_33 AC 7 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 7 ms
4,380 KB
testcase_37 AC 6 ms
4,380 KB
testcase_38 AC 8 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int>sorted;
vector<int>work;
vector<int> box,item;
int res=11;
int N,M;
void check(int sz){
	for(auto &it:work){
		sorted.push_back(it);
	}
	sort(sorted.begin(),sorted.end());
	reverse(sorted.begin(),sorted.end());
	bool f=true;
	for(auto i=0;i<sz;i++){
		if(sorted[i]>box[i])f=false;
	}
	if(f)res=sz;
	sorted.clear();
}

void func(int n,int sz){
	if(sz>=res)return;
	if(n==N){
		check(sz);
		return;
	}
	for(int i=0;i<sz;i++){
		work[i]+=item[n];
		func(n+1,sz);
		work[i]-=item[n];
	}
	work.push_back(item[n]);
	func(n+1,sz+1);
	work.pop_back();
}

int main(){
	sorted.reserve(10);
	work.reserve(10);
	cin>>N;
	for	(int i=0;i<N;i++){
		int x;
		cin>>x;
		item.push_back(x);
	}
	cin>>M;
	for	(int i=0;i<M;i++){
		int x;
		cin>>x;
		box.push_back(x);
	}
	sort(box.begin(),box.end());
	reverse(box.begin(),box.end());
	func(0,0);
	if(res>=11)cout<<-1<<endl;
	else cout<<res<<endl;
}
0