結果

問題 No.50 おもちゃ箱
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-14 00:10:40
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 802 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 149,176 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 20:04:53
合計ジャッジ時間 4,061 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

bool dp[1 << 10];
bool dp2[1 << 10];

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	int M;
	cin >> M;
	vector<int> B(N);
	for (int i = 0; i < M; i++)
	{
		cin >> B[i];
	}

	sort(B.begin(), B.end());
	reverse(B.begin(), B.end());
	dp[0] = true;

	for (int i = 0; i < M; i++)
	{
		for (int j = 0; j < (1 << N); j++)
		{
			int c = 0;
			for (int k = 0; k < N; k++)
			{
				if ((j >> k) % 2 == 0) continue;
				c += A[k];
			}
			if (c > B[i]) continue;

			for (int k = (1 << N) - 1; k >= 0; k--)
			{
				dp2[j | k] |= dp[k];
			}
		}

		for (int k = (1 << N) - 1; k >= 0; k--)
		{
			dp[k] = dp2[k];
		}
		if (dp[(1 << N) - 1]){
			cout << (i + 1) << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}
0