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 sz(x) int(x.size())
#define all(x) begin(x),end(x)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--)
#define dforn(i,n) for(int i=int(n)-1;i>=0;i--)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
//const int MAXN = 2e5+5;
//const ll INF = 1e18;
const int MOD = 1e9+7;
template<class x> ostream & operator<<(ostream & out, vector<x> v){
out<<"[ ";
for(auto y : v) out<<y<<" ";
out<<"]";
return out;
}
int sum[1 << 20];
bool dp[21][1 << 20];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
vector<int> s[1001];
for (int mask = 1; mask < 1 << m; mask++) {
if (mask != 0) {
int i = __builtin_ctz(mask);
sum[mask] = sum[mask ^ (1 << i)] + b[i];
}
if (sum[mask] <= 1000) {
s[sum[mask]].push_back(mask);
}
dp[0][mask] = true;
}
for (int i = 0; i < n; i++) {
for (int mask = 0; mask < 1 << m; mask++) {
for (int submask : s[a[i]]) {
if ((mask & submask) == submask) {
dp[i + 1][mask] |= dp[i][mask ^ submask];
}
}
}
}
bool ans = false;
for (int mask = 0; mask < 1 << m; mask++) {
ans |= dp[n][mask];
}
if (ans) cout << "YES\n";
else cout << "NO\n";
return 0;
}
# | 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... |