# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
671842 | Baytoro | Bank (IZhO14_bank) | C++17 | 79 ms | 16968 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 ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
//#define int long long
#define endl '\n'
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const int INF=1e9,mod=1e9+7;
int dp[(1<<20)+5];
int ok[(1<<20)+5];
vector<int> f(vector<int> a, vector<int> b){
memset(ok,-1,sizeof(ok));
memset(dp,0,sizeof(ok));
int n=a.size();
int m=b.size();
vector<int> ans;
for(int i=0;i<n;i++){
for(int mask=1;mask<(1<<m);mask++){
for(int j=0;j<m;j++){
if(mask&(1<<j)){
//cout<<ok[(mask^(1<<j))]<<endl;
if(ok[mask^(1<<j)]<i-1) continue;
dp[mask]=(dp[mask^(1<<j)])+b[j];
//get(mask);
//cout<<j<<' '<<
if(dp[mask]>a[i]) continue;
ok[mask]=i-1;
if(dp[mask]==a[i]){
dp[mask]=0;
ok[mask]=i;
//get(mask);
if(i==n-1){
ans.pb(mask);
}
}
break;
}
}
}
}
return ans;
}
int n,m;
void solve(){
cin>>n>>m;
vector<int> a(n+1),b(m+1);
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<m;i++) cin>>b[i];
vector<int> tmp;
for(int i=0;i<n/2;i++) tmp.pb(a[i]);
vector<int> ans1=f(tmp,b);
tmp.clear();
for(int i=n/2;i<n;i++)
tmp.pb(a[i]);
vector<int> ans2=f(tmp,b);
//cout<<ans2.size()<<endl;
if(ans1.size()==0){
if(ans2.size()>0){
cout<<"YES\n";
return;
}
}
for(auto i: ans1){
for(auto j: ans2){
if(!(i&j)){
cout<<"YES\n";
return;
}
}
}
cout<<"NO\n";
}
main(){
ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}
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... |