// Time:
// Algorithms:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // pbds
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
using namespace std;
#define MAXN 200005
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORR(j, i, n) for (int i = j; i < n; i++)
#define FORD(i, n) for (int i = n - 1; i >= 0; i--)
#define F1R(i, n) for (int i = 1; i <= n; i++)
#define F1RD(i, n) for (int i = n; i >= 1; i--)
#define pb push_back
#define mp make_pair
#define endl '\n'
#define DUEHOANG \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
#define fileio(in, out) \
freopen(in, "r", stdin); \
freopen(out, "w", stdout);
#define ll long long
#define MOD (1e9*1)+7
#define MOD2 998244353
#define INF (1e9*1)+5
typedef set<int> si;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> iii;
typedef vector<pii> vii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef deque<int> di;
typedef map<int, int> mii;
// ordered_set
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> os;
#define f first
#define s second
#define LEFT(x) 2 * x
#define RIGHT(x) 2 * x + 1
#define bitinc(x) x&-x
const int MAX(int &a, int b)
{
return a = max(a, b);
}
const int MIN(int &a, int b)
{
return a = min(a, b);
}
int n, m, a[25], b[25];
pii dp[(1 << 20) + 5];
void solve()
{
cin >> n >> m;
FOR(i, n) cin >> a[i];
FOR(i, m) cin >> b[i];
FOR(k, (1<<m))
{
FOR(i, m)
{
if(k & (1 << i))
{
pii nx = dp[k ^ (1 << i)];
nx.s += b[i];
if(nx.s == a[nx.f])
{
++nx.f;
nx.s = 0;
}
dp[k] = max(dp[k], nx);
}
}
if(dp[k].f == n)
{
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
signed main()
{
DUEHOANG;
int t = 1;
// cin >> t; // uncomment if it's multitest
while(t--)
{
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
86 ms |
8476 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
86 ms |
8568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
86 ms |
8476 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
86 ms |
8568 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
2 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
100 ms |
8568 KB |
Output is correct |
32 |
Correct |
107 ms |
8568 KB |
Output is correct |
33 |
Correct |
115 ms |
8560 KB |
Output is correct |
34 |
Correct |
96 ms |
8572 KB |
Output is correct |
35 |
Correct |
97 ms |
8568 KB |
Output is correct |
36 |
Correct |
91 ms |
8568 KB |
Output is correct |
37 |
Correct |
95 ms |
8568 KB |
Output is correct |
38 |
Correct |
90 ms |
8568 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
90 ms |
8472 KB |
Output is correct |
41 |
Correct |
87 ms |
8568 KB |
Output is correct |
42 |
Correct |
123 ms |
8568 KB |
Output is correct |
43 |
Correct |
97 ms |
8572 KB |
Output is correct |
44 |
Correct |
90 ms |
8568 KB |
Output is correct |
45 |
Correct |
1 ms |
384 KB |
Output is correct |
46 |
Correct |
113 ms |
8536 KB |
Output is correct |
47 |
Correct |
89 ms |
8568 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
86 ms |
8568 KB |
Output is correct |
50 |
Correct |
101 ms |
8568 KB |
Output is correct |
51 |
Correct |
97 ms |
8568 KB |
Output is correct |
52 |
Correct |
95 ms |
8568 KB |
Output is correct |
53 |
Correct |
109 ms |
8568 KB |
Output is correct |
54 |
Correct |
115 ms |
8508 KB |
Output is correct |
55 |
Correct |
100 ms |
8568 KB |
Output is correct |
56 |
Correct |
100 ms |
8696 KB |
Output is correct |
57 |
Correct |
99 ms |
8568 KB |
Output is correct |
58 |
Correct |
99 ms |
8568 KB |
Output is correct |