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>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;
int vis[1<<20],n,mo,a[21],m[20],val[1<<20],x;
vector<int> v[20005],ans[21];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>mo;
for(int i=1;i<=n;++i) {
cin>>a[i];
a[i]+=a[i-1];
}
for(int i=0;i<mo;++i)
cin>>m[i];
for(int i=0;i<(1<<mo);++i) {
vis[i]=1;
for(int j=0;j<mo;++j)
if((1<<j)&i)
val[i]+=m[j];
v[val[i]].pb(i);
}
for(int i=1;i<=n;++i) {
for(int j=0;j<v[a[i]].size();++j) {
if(vis[v[a[i]][j]])
ans[i].pb(v[a[i]][j]);
}
memset(vis,0,sizeof vis);
for(int j=0;j<ans[i].size();++j) {
vis[ans[i][j]]=1;
}
for(int j=0;j<(1<<mo);++j) {
if(!vis[j])
continue;
for(int k=0;k<mo;++k)
if(!(j&(1<<k)))
vis[j|(1<<k)]=1;
}
}
if(ans[n].size()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<v[a[i]].size();++j) {
~^~~~~~~~~~~~~~~
bank.cpp:38:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<ans[i].size();++j) {
~^~~~~~~~~~~~~~
# | 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... |