# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1001488 | reginox | Bank (IZhO14_bank) | C++17 | 77 ms | 46612 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 ll long long
#define ld long double
#define all(v) begin(v), end(v)
#define pi pair<int, int>
#define vi vector<int>
#define task "test"
using namespace std;
const int maxn = 20;
ll n,m,dp[1<<21],a[21],b[21];
vi v[1000005];
int main(){
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(ll i = 0; i < n; i++) cin >> a[i];
for(ll i = 0; i < m; i++) cin >> b[i];
for(ll msk = 1; msk < 1<<m; msk++){
ll sum = 0;
for(ll i = 0; i < m; i++){
if(msk>>i&1) sum += b[i];
}
v[sum].push_back(msk);
}
memset(dp,-1,sizeof(dp));
dp[0] = 0;
for(ll i = 0; i < n; i++){
for(ll msk = 0; msk < 1<<m; msk++){
if(dp[msk] == 1) continue;
for(ll sub:v[a[i]]){
if(sub & msk) continue;
dp[sub|msk] = dp[msk]+1;
if(dp[sub|msk] == n){
cout << "YES";
return 0;
}
}
}
}
cout << "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... |