# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073106 | vjudge1 | Bank (IZhO14_bank) | C++17 | 1 ms | 348 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>
using namespace std;
#define ll long long
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
const ll MOD=1000000007;
int n,m,a[20],b[20];
unordered_map<ll,bool>was[21];
vector<int>v[1001];
bool f(int cur=0, int used=0){
if(was[cur][used]) return 0;
if(cur==n) return 1;
was[cur][used]=1;
for(int y:v[a[cur]]) if(y&used==0) if(f(cur+1,used+y)) return 1;
return 0;
}
void solve(){
cin>>n>>m;
for(int i=0; i<n; i++) cin>>a[i];
for(int i=0; i<m; i++) cin>>b[i];
for(int i=1; i<(1<<m); i++){
int sum=0;
for(int j=0; j<m; j++) if((1<<j)&i) sum+=b[j];
if(sum<=1000) v[sum].pb(i);
}
if(f()) cout<<"YES";
else cout<<"NO";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin>>t;
for(int _=0; _<t; _++){
// cout<<"Case "<<_+1<<":\n";
solve();
}
return 0;
}
//080129552180
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... |