# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056575 | vjudge1 | Bank (IZhO14_bank) | C++14 | 77 ms | 19888 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 int long long
#define emb emplace_back
#define ii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=21+5,mod=1e9+7;
int n,M[N],ans,m,a[N],b[N];
bool k[(1<<21)+5];
ii f[(1<<21)+5];
bool on(int mask,int i){
return (mask>>1)&1;
}
int ex(int mask,int i){
return mask^(1<<i);
}
main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
if(fopen("bank.in","r")){
freopen("bank.in","r",stdin);
freopen("bank.out","w",stdout);
}
cin >> n >> m;
for(int i=1;i<=n;++i)cin >> a[i];
for(int i=0;i<m;++i)cin >> b[i];
f[0]={1,0};
k[0]=1;
for(int mask=1;mask<(1<<m);++mask){
for(int i=0;i<m;++i){
if(mask&(1<<i))
if(k[mask^(1<<i)]){
ii res=f[mask^(1<<i)];
res.se+=b[i];
if(res.se<a[res.fi]){
k[mask]=true;
f[mask]=res;
}
else{
if(res.se==a[res.fi]){
k[mask]=true;
f[mask]={res.fi+1,0};
}
}
//cout<<i<<'\n';
}
}
}
for(int i=1;i<(1<<m);++i){
if(f[i].fi>n){
cout<<"YES";
return 0;
}
}
cout <<"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... |