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>
#define name "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define pb push_back
#define all(v) v.begin(), v.end()
#define maxn
const int M = 1e9 + 7;
using namespace std;
int n, m, id[1003], a[22];
bool dp[22][1 << 20];
vector <int> luu[22];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
// freopen(name".in", "r", stdin);
// freopen(name".out", "w", stdout);
cin >> n >> m;
fi(i, 1, n){
int x; cin >> x;
id[x] = i;
}
fi(i, 1, m) cin >> a[i];
fi(msk, 1, (1 << m) - 1){
int sum = 0;
fi(i, 0, m - 1) if(getbit(msk, i)) sum += a[i + 1];
if(sum <= 1000 && id[sum] != 0) luu[id[sum]].pb(msk);
}
fi(i, 1, n) if(luu[i].size() == 0) {cout << "NO"; return 0;}
vector <int> pre;
pre.pb(0);
fi(i, 1, n){
vector <int> tmp;
for(auto msk: pre){
for(auto tt: luu[i]) if((msk & tt) == 0){
tmp.pb(msk + tt);
}
}
if(i == n && tmp.size() != 0) {cout << "YES"; return 0;}
swap(pre, tmp);
}
cout << "NO";
}
# | 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... |