# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1068460 | vjudge1 | Bank (IZhO14_bank) | C++17 | 1 ms | 348 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.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
vector<int>v[20];
int n;
bool calc(int msk=0, int cur=0){
if(cur==n) return 1;
bool res=0;
for(int i=0; i<v[cur].size(); i++){
if(__builtin_popcount(v[cur][i]|msk)==__builtin_popcount(msk)+__builtin_popcount(v[cur][i])){
res|=calc(v[cur][i]|msk,cur+1);
}
}
return res;
}
void solve(){
int m;
cin>>n>>m;
int a[n],b[m];
for(int i=0; i<n; i++) cin>>a[i];
for(int i=0; i<m; i++) cin>>b[i];
sort(b,b+m);
for(int i=0; i<n; i++){
for(int j=1; j<(1<<m); j++){
int sum=0;
for(int k=0; k<m; k++) if((1<<k)&j) sum+=b[k];
if(sum>a[i]) break;
if(sum==a[i]) v[i].pb(j);
}
}
if(calc()) cout<<"YES";
else cout<<"NO";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin>>t;
for(int _=0; _<t; _++){
// cout<<"Case "<<_+1<<":\n";
solve();
}
return 0;
}
//080129552180
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... |