# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
337557 | Kerim | Bank (IZhO14_bank) | C++17 | 216 ms | 89068 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 MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dp[20][1<<20];
vector<int>adj[1024];
int a[20],b[20];
int rec(int pos,int mask){
if(pos<0)
return 1;
int &ret=dp[pos][mask];
if(~ret)
return ret;
tr(it,adj[a[pos]])
if(!(mask&(*it)) and rec(pos-1,mask^(*it)))
return ret=1;
/*
for(int sub=mask;sub;--sub,sub&=mask)
if(cost[sub]==a[pos] and rec(pos-1,mask^sub))
return ret=1;
*/
return ret=0;
}
int main(){
// freopen("file.in", "r", stdin);
int n,m;
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=0;i<(1<<m);i++){
int sum=0;
for(int j=0;j<m;j++)
if(i>>j&1)
sum+=b[j];
if(sum<=1000)
adj[sum].pb(i);
}
memset(dp,-1,sizeof dp);
if(rec(n-1,0))
puts("YES");
else
puts("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... |