# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968840 | HaciyevAlik | Bank (IZhO14_bank) | C++14 | 300 ms | 179168 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;
const int sz=21;
int n,m,a[sz],b[sz],dp[sz][1<<sz];
vector<int> v[1005];
bool solve(int mask,int i) {
if(i==n) {
return true;
}
if(dp[i][mask]!=-1) {
return dp[i][mask];
}
for(int j=0;j<v[a[i]].size();++j) {
int cur=v[a[i]][j];
if((mask&cur)==cur && solve(mask^cur,i+1)==1) {
return dp[i][mask]=true;
}
}
return dp[i][mask]=false;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i=0;i<n;++i) {
cin >> a[i];
}
for(int i=0;i<m;++i) {
cin >> b[i];
}
memset(dp,-1,sizeof(dp));
for(int mask=0;mask<(1<<m);++mask) {
int cur=0;
for(int i=0;i<m;++i) {
if(mask>>i&1) {
cur += b[i];
}
}
if(cur>1000) continue;
v[cur].push_back(mask);
}
solve((1<<m)-1,0);
if(dp[0][(1<<m)-1]) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
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... |