結果

問題 No.50 おもちゃ箱
ユーザー akusyounin2412akusyounin2412
提出日時 2019-03-25 19:11:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,604 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 130,668 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 09:32:12
合計ジャッジ時間 6,517 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = 1LL << 60;//numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f[200000];
LL n, m, s, t, h, w, k, q, p, ans, sum, cnt, a[20], b[20], dp[20][1 << 10];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	cin >> m;
	rep(i, m) {
		cin >> b[i];
	}
	sort(a, a + n, [](LL x, LL y) {return x > y; });
	sort(b, b + m, [](LL x, LL y) {return x > y; });
	dp[0][0] = 1;
	for (int i = 0; i < m; i++) {
		for (int mask = 0; mask < (1 << n); mask++) {
			for (int get = 0; get < (1 << n); get++) {
				if (get&mask != 0)continue;
				int sum = 0;
				rep(j, n)if (get&(1 << j))sum += a[j];
				if (sum <= b[i])
					dp[i + 1][mask | get] = (dp[i][mask] | dp[i + 1][mask | get]);
			}
		}
	}
	rep(i, m+1) {
		if (dp[i][(1 << n) - 1]) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}
0