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 comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define ld long double
#define ar array
const int INF = 1e15;
const int MOD = 1e9+7;
const int LIMIT = 1e18;
const int MXN = 21;
int a[MXN], b[MXN];
vector<int> smh[1005*MXN];
set<int> dp[MXN];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m; cin>>n>>m;
for (int i = 0; i < n; i++) cin>>a[i];
for (int i = 0; i < m; i++) cin>>b[i];
for (int i = 0; i < 1<<m; i++) {
int sum = 0;
for (int j = 0; j < m; j++) if ((i>>j) & 1) {
sum += b[j];
}
smh[sum].push_back(i);
}
dp[0] = {0};
for (int i = 0; i < n; i++) {
for (int j : dp[i]) {
for (int x : smh[a[i]]) if ((j & x) == 0) {
dp[i+1].insert(j ^ x);
}
}
}
if (dp[n].size() > 0) {
cout<<"YES\n";
} else cout<<"NO\n";
}
Compilation message (stderr)
bank.cpp:3: warning: ignoring #pragma comment [-Wunknown-pragmas]
3 | #pragma comment(linker, "/stack:200000000")
|
# | 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... |