# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
191345 | rzbt | Bank (IZhO14_bank) | C++14 | 82 ms | 504 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 mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 21
typedef long long ll;
using namespace std;
int n,m;
int a[MAXN],b[MAXN];
vector<int> moze[MAXN];
bool dp[MAXN][1<<MAXN];
void resi(int koji,int maska){
//printf(" %d %d\n",koji,maska);
if(koji==n){
printf("YES");
exit(0);
}
if(dp[koji][maska])return;
dp[koji][maska]=true;
for(auto x:moze[koji])
if(!(x & maska) && !dp[koji+1][x|maska])
resi(koji+1,x|maska);
}
int main()
{
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<(1<<m);i++){
int zbir=0;
for(int j=0;j<m;j++){
if(i&(1<<j)){
zbir+=b[j];
}
}
//printf(" %d %d\n",i,zbir);
for(int j=0;j<n;j++)
if(a[j]==zbir)moze[j].pb(zbir);
}
resi(0,0);
printf("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... |