# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
68556 | hamzqq9 | Bank (IZhO14_bank) | C++14 | 194 ms | 18940 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 st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 100000000
#define MOD 1000000007
#define N 400005
#define MAX 10000006
#define LOG 30
#define KOK 200
using namespace std;
int n,m;
int a[21],b[21],sum[pw(21)];
bool vis[21][pw(20)];
vector<int> okey[21];
void dfs(int now,int mask) {
if(now==n) {
printf("YES");
exit(0);
}
if(vis[now][mask]) return ;
vis[now][mask]=1;
for(int i:okey[now]) {
if(mask&i) continue ;
dfs(now+1,mask|i);
}
}
int main() {
// freopen("input.txt","r",stdin);
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++) {
scanf("%d",&a[i]);
}
for(int i=0;i<m;i++) {
scanf("%d",&b[i]);
}
for(int i=1;i<pw(m);i++) {
for(int j=0;j<m;j++) {
if(i&pw(j)) {
sum[i]=sum[i-pw(j)]+b[j];
break ;
}
}
}
for(int i=0;i<n;i++) {
for(int j=0;j<pw(m);j++) {
if(sum[j]==a[i]) {
okey[i].pb(j);
}
}
}
dfs(0,0);
printf("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... |