This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define pb push_back
#define int long long
#define no "NO\n"
#define yes "YES\n"
#define ew "\n"
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define float long double
#define len(x) (int)x.size()
#define macvin \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using pii = pair<int, int>;
using ld = long double;
const int N = 1e5 + 1;
const int mod = 1e9 + 7;
const int inf = 1e18 + 7;
const int hh = 1e2 + 70;
const int MAX = 200007;
const int maxn = 1e6 + 7;
int n, k;
int a[21], b[21];
int used[21][(1 << 20)];
vector<int> mp[1001];
void recursiaaa(int i, int sum)
{
if (i == n)
{
cout << yes;
exit(0);
}
if (used[i][sum])
{
return;
}
used[i][sum] = 1;
for (int x : mp[a[i]])
{
if (sum + x == (sum | x))
{
recursiaaa(i + 1, sum + x);
}
}
}
void iamgoingto10of10()
{
cin >> n >> k;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 0; i < k; i++)
{
cin >> b[i];
}
for (int mask = 0; mask < (1 << k); mask++)
{
int sum = 0, x = mask, id = 0;
while (x)
{
if (x & 1)
{
sum += b[id];
}
id++;
x >>= 1;
}
if (sum <= 1000)
{
mp[sum].pb(mask);
}
}
recursiaaa(0, 0);
cout << no;
}
signed main()
{
{
macvin int T = 1;
// cin >> T;
while (T--)
{
iamgoingto10of10();
}
}
}
/*
⣿⣿⣿⣿⣿⣿⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣤⣤⠤⠤⠀⠒⠶⣀⠀⠀⠀⠈⣿⣿⣿⡿⠁
⣿⣿⣿⣿⣿⡗⠈⠀⠀⠀⣠⢀⣀⠀⣀⠀⢀⡀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠶⠚⣛⣉⠠⠀⣄⣀⠀⠀⠀⠀⠀⠀⠀⢿⣿⡿⠁⠀
⠃⠀⠀
⠀⣿⣼⡟⣿⣿⠀⢀⠢⠁⠀⣰⣜⣿⢿⣿⠿⢿⠟⢕⠢⠀⠃⠀⠀⠀⠀⠀⠀⠀⠐⠁⠈⠒⠒⠁⠀⠈⠅⠀⠀⠀⠀⠀⠀⡘⠟⢀⠀⠀
⠲⣿⢧⡃⣽⣿⠂⠀⠀⠀⠀⠉⠟⠉⠠⠈⠁⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠺⠀⠀⠀⠀
⠀⡹⠸⣇⢸⣿⡅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠆⠀⠀⠀
⢠⡇⠀⣿⡘⢿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀
⣼⣯⡈⠈⢯⠎⠻⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀
⣿⣷⣿⣆⢘⣆⠀⣷⢁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷⠮⠁⠀⠀
⣿⣿⣿⣿⣶⣌⠦⣜⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠀⣀⡄⠀⠀⠀⣰⣤⡠⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⢋⠄⠀⢀⢠
⣿⣿⣿⣿⣿⣿⣷⣎⣗⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢛⠙⠛⡈⠀⠜⠈⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡂⢠⡴⣏⢧
⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷⢿⡱⣏⠖
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠠⢤⣤⣤⣤⣄⣀⣠⣀⣠⠶⠴⠦⠤⠒⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡿⣏⠷⠈⠌
⠀⠌⠙⠻⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢺⠟⠀⠀⠀⠀
⠀⠀⠀⠀⢉⠻⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠀⡈⠇⠀⠀⠀⠀
⠀⠀⠀⠀⠈⠉⠙⠻⢿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠔⠇⢠⠃⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⣦⡀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠁⠀⢠⠎⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⣿⢹⣿⣞⡄⡀⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠎⠀⠀⣀⠔⠁⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣈⢻⣿⣧⣗⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⢖⡡⠔⣠⡰⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣼⣿⡏⠈⣿⡿⠁⠀⠀⠽⢿⣿⣾⣽⡷⣦⢤⡀⡄⣀⠀⡀⡀⠄⠔⣒⢱⣜⣮⡴⠚⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣾⣿⣿⡇⠀⢿⠁⠀⠀⠀⠀⠈⠙⣿⣿⣿⣿⣯⣷⡬⣫⡀⡱⣀⣖⣼⣾⣿⠟⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠻⡟⠙⡷⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⣿⣷⣿⣿⣿⣿⠿⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⡇⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣻⣟⢿⣿⠟⣋⡀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠹⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⢛⣽⣴⢴⣟⢙⣿⣦⡙⠑⠓⠙⠃⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |