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, 1, m) if(getbit(msk, i - 1)) sum += a[i];
if(sum <= 1000 && id[sum] != 0) luu[id[sum]].pb(msk);
}
fi(i, 1, n) if(luu[i].size() == 0) {cout << "NO"; return 0;}
dp[0][0] = 1;
fi(i, 1, n){
fi(msk, 0, (1 << m) - 1) if(dp[i - 1][msk]){
for(auto tt: luu[i]) if((msk & tt) == 0){
dp[i][msk + tt] = 1;
}
}
}
fi(msk, 1, (1 << m) - 1) if(dp[n][msk]) {cout << "YES"; return 0;}
cout << "NO";
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:33:38: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
33 | fi(i, 1, m) if(getbit(msk, i - 1)) sum += a[i];
| ~~^~~
bank.cpp:9:29: note: in definition of macro 'getbit'
9 | #define getbit(i, j) ((i >> j) & 1)
| ^
# | 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... |