# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
843837 | Elvin_Fritl | Bank (IZhO14_bank) | C++17 | 1058 ms | 600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
const int N = 25;
vector<int>a(N),b(N);
int n,m;
bool func(int ind,int x){
///cerr << ind << " " << x << endl;
if(ind == n){
return true;
}
if(x == (1<<m)){
return false;
}
vector<int>next;
for(int i=0;i<m;i++){
if((x&(1<<i)) == 0){
next.push_back(i);
}
}
///cerr << next.size() << endl;
bool as = false;
for(int mask=1;mask<(1<<(next.size()));mask++){
if(as == true){
break;
}
int sum = 0,z = x;
for(int i=0;i<next.size();i++){
if(mask&(1<<i)){
///cerr << 1;
sum += b[next[i]];
z += (1<<next[i]);
}
else{
///cerr << 0;
}
}
///cerr << endl;
if(sum == a[ind]){
///cerr << mask << endl;
as |= func(ind+1,z);
}
}
return as;
}
int32_t main()
{
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
bool res = func(0,0);
if(res == true){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
return 0;
}
/*
1 1 2 2 3 3 4 4
1
*/
Compilation message (stderr)
# | 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... |