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;
#define ll long long
#define ld long double
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define all(v) v.begin(), v.end()
#define test() \
int _t; \
cin >> _t; \
while (_t--)
#define testig() \
int _t; \
cin >> _t; \
cin.ignore(); \
while (_t--)
#define binarys(l, r, lv, rv, mid) for (int l = lv, r = rv, mid = (l + r) >> 1; l <= r; mid = (l + r) >> 1)
#define fi first
#define se second
#define clz(n) 31 - __builtin_clz(n)
#define vec2d(n, m) vector<vector<int>>(n + 1, vector<int>(m + 1, 0))
template <class T, class P>
bool maximize(T &a, P b) {
if (a < b)
return a = b, true;
return false;
}
template <class T, class P>
bool minimize(T &a, P b) {
if (a > b)
return a = b, true;
return false;
}
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int iinf = 0x3f3f3f3f;
const int maxn = 1e5 + 69;
const int mod = 998244353;
const int base = 311;
int n, m, ln;
int A[21], B[21], id[1001];
set<int> b;
vector<int> a[1001];
ll bit = 0;
bool res = false;
string rs[] = {"NO", "YES"};
void bt(int p = 1){
for(int i: a[A[p]]){
if(bit & i) continue;
bit ^= i;
if(p == n){
res = true;
return;
}
else bt(p + 1);
if(res) return;
bit ^= i;
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("main.inp", "r")) {
freopen("main.inp", "r", stdin);
freopen("main.out", "w", stdout);
}
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> A[i];
maximize(ln, A[i]);
}
a[0].pub(0);
b.insert(0);
vector<int> c;
for(int i = 0; i < m; i++){
cin >> B[i];
if(B[i] > ln) continue;
for(int j: b){
if(j + B[i] > ln) continue;
c.pub(j + B[i]);
for(int v: a[j]) a[j + B[i]].pub(v | (1 << i));
}
while(c.size()){
b.insert(c.back());
c.pob();
}
}
bt();
cout << rs[res];
return 0;
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen("main.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | freopen("main.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |