#include <bits/stdc++.h>
using namespace std;
const int MAXN = 21;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N,M; cin >> N >> M;
vector<int> arr(N),bank(M);
for(int i = 0;i<N;++i) cin >> arr[i];
for(int i = 0;i<M;++i) cin >> bank[i];
vector<vector<int>> poss(1001);
for(int i = 1;i<(1<<M);++i){
int cur = 0;
for(int j = 0;j<M;++j){
if((1<<j)&i){
cur += bank[j];
}
}
poss[cur].push_back(i);
}
vector<int> dp((1<<M),-1); dp[0] = 0;
for(int i = 0;i<N;++i){
for(int j = (1<<M)-1;j>=0;--j){
if(dp[j] == -1) continue;
for(auto t : poss[arr[i]]){
if(!(t&j)){
dp[t|j] = dp[j]+1;
if(dp[t|j] == N){
cout << "YES\n";
return 0;
}
}
}
}
}
cout << "NO\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Runtime error |
4 ms |
1372 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Runtime error |
4 ms |
1372 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |