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;
int n, m;
int a[1000];
int b[1000];
vector<int> d1[1024];
vector<int> d2[1024];
int sum[1<<20];
int main() {
//freopen("bank.in", "r", stdin);
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++) {
for(int j = 0; (1<<j) <= i; j++) {
if((i & (1<<j)) != 0) sum[i] += b[j];
}
}
int x = (n + 1)/2;
int y = n/2;
for(int i = 0; i < x; i++) {
for(int j = 0; j < (1<<m); j++) {
if(sum[j] == a[i]) d1[1<<i].push_back(j);
}
}
d1[0].push_back(0);
for(int i = 1; i < (1<<x); i++) {
for(int j = 0; (1<<j) <= i; j++) {
if(i == (1<<j)) continue;
if((i & (1<<j)) != 0) {
for(int l: d1[1<<j]) {
for(int k: d1[i - (1<<j)]) {
if((l & k) == 0) d1[i].push_back(l + k);
}
}
}
}
}
for(int i = 0; i < y; i++) {
for(int j = 0; j < (1<<m); j++) {
if(sum[j] == a[i + x]) d2[1<<i].push_back(j);
}
}
d2[0].push_back(0);
for(int i = 1; i < (1<<y); i++) {
for(int j = 0; (1<<j) <= i; j++) {
if(i == (1<<j)) continue;
if((i & (1<<j)) != 0) {
for(int l: d2[1<<j]) {
for(int k: d2[i - (1<<j)]) {
if((l & k) == 0) d2[i].push_back(l + k);
}
}
}
}
}
for(int i: d1[(1<<x) - 1]) {
for(int j: d2[(1<<y) - 1]) {
if((i & j) == 0) {
cout << "YES";
return 0;
}
}
}
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... |