# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
850638 | askow | Bank (IZhO14_bank) | C++14 | 1030 ms | 41284 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>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
//!!! dp[i][mask] da li je moguce u prvih i napraviti tako da iskoristim tacno mask bitove
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
int b[m];
for(int i=0;i<m;i++)cin>>b[i];
int dp[n+1][(1LL<<m)];
for(int i=0;i<=n;i++)for(int j=0;j<(1LL<<m);j++)dp[i][j]=0;
for(int i=0;i<(1LL<<m);i++){
int R=0;
for(int j=0;j<m;j++){
if(i&(1LL<<j))R+=b[j];
}
if(R==a[0])dp[0][i]=1;
}
/*
int ans=0;
for(int i=0;i<(1LL<<m);i++)ans|=(dp[0][i]);
if(ans)cout<<"YES";
else cout<<"NO";*/
int pref[(1LL<<m)];
for(int i=0;i<(1LL<<m);i++)pref[i]=0;
for(int i=0;i<(1LL<<m);i++){
int R=0;
for(int j=0;j<m;j++){
if(i&(1LL<<j))R+=b[j];
}
pref[i]=R;
}
for(int i=1;i<n;i++){
//!!! dp[i][mask]|=dp[i-1][drugamaska];
//!!! i&j==0 nemaju zajednicki bit
int R=0;
for(int j=0;j<(1LL<<m);j++){
// za iti broj ces uzeti ovu masku
if(pref[j]==a[i]){
//!!! ovu masku koristim da bi dobio a[i]
//!!! sada me zanima dal mogu da od neke druge maske koja nema nijedan bit isti da dobijem sve i-1 brojeve
for(int mask=0;mask<(1LL<<m);mask++){
if(mask&j)continue;
dp[i][mask|j]|=(dp[i-1][mask]);
}
}
}
}
int ans=0;
for(int i=0;i<(1LL<<m);i++)ans|=dp[n-1][i];
if(ans)cout<<"YES";
else cout<<"NO";
}
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... |