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 f[2000009];
int A[2000009], B[2000009];
long long C[2000009];
void CO(vector<int> &a, vector<int> b){
for(int i = 0; i < (1 << m); i++)
A[i] = 0, B[i] = 0;
for(int i = 0; i < a.size(); i++)
A[a[i]] = 1;
for(int i = 0; i < b.size(); i++)
B[b[i]] = 1;
for(int i = 0; i < m; i++)
for(int j = 0; j < (1 << m); j++)
if(j & (1 << i))
A[j] += A[j ^ (1 << i)],
B[j] += B[j ^ (1 << i)];
for(int i = 0; i < (1 << m); i++)
C[i] = A[i] * B[i];
for(int i = 0; i < m; i++)
for(int j = 0; j < (1 << m); j++)
if(j & (1 << i))
C[j] -= C[j ^ (1 << i)];
a.clear();
for(int i = 0; i < (1 << m); i++)
if(C[i]) a.push_back(i);
}
int aa[1009], bb[1009];
vector<int> v[29];
main(){
int N, M;
vector<int> a, b;
cin >> N >> M;
int sa = 0;
for(int i = 0; i < N; i++){
int k;
cin >> k;
aa[k] ++;
}
for(int i = 0; i < M; i++){
int k;
cin >> k;
bb[k] ++;
}
for(int i = 0; i <= 1000; i++){
for(int j = min(aa[i], bb[i]); j < aa[i]; j++)
a.push_back(i);
for(int j = min(aa[i], bb[i]); j < bb[i]; j++)
b.push_back(i);
}
n = a.size(); m = b.size();
for(int i = 0; i < n; i++){
sa += a[i];
}
if(2 * n > m) {
cout << "NO" << endl;
return 0;
}
if(n == 0){
cout << "YES" << endl;
return 0;
}
for(int i = 0; i < (1 << m); i++){
int S = 0, k = 0;
for(int j = 0; j < m; j++){
if((1 << j) & i)
S += b[j], k++;
}
if(S == sa) f[i] = 1;
if(k > m - n + 1) continue;
for(int j = 0; j < n; j++){
if(a[j] == S) v[j].push_back(i);
}
}
vector<int> V;
V.push_back(0);
for(int i = 0; i < n; i++){
CO(V, v[i]);
}
for(int i = 0; i < V.size(); i++){
if(f[V[i]]){
cout <<"YES"<<endl;
return 0;
}
}
cout << "NO" << endl;
}
Compilation message (stderr)
bank.cpp: In function 'void CO(std::vector<int>&, std::vector<int>)':
bank.cpp:10:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < a.size(); i++)
~~^~~~~~~~~~
bank.cpp:12:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < b.size(); i++)
~~^~~~~~~~~~
bank.cpp: At global scope:
bank.cpp:31:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
bank.cpp: In function 'int main()':
bank.cpp:81:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < V.size(); i++){
~~^~~~~~~~~~
# | 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... |