# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
656387 | iskhakkutbilim | Bank (IZhO14_bank) | C++14 | 1095 ms | 8096 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 int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int M = 1e9 + 7;
const int N = 21;
int dp[N][1<<N], a[N], b[N];
int n, m;
vector<int> g[N];
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
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 mask = 0; mask < (1<<m); mask++){
int sum = 0;
for(int i = 0;i < m; i++){
if(mask & (1<<i)){
sum+= b[i];
}
}
for(int i = 0;i < n; i++){
if(a[i] == sum){
g[i].push_back(mask);
}
}
}
for(int i = 0;i < n; i++){
if(g[i].empty()){
cout << "NO";
return 0;
}
}
for(auto x : g[0]){
dp[0][x] = 1;
}
for(int i = 1;i < n; i++){
for(int mask = 0; mask < (1<<m); mask++){
// if(dp[i-1][mask] == 0){
// continue;
// }
for(auto x : g[i]){
if((mask & x) == 0 and dp[i-1][mask]==1){
dp[i][mask|x] = 1;
}
}
}
}
for(int mask = 1; mask < (1<<m); mask++){
if(dp[n-1][mask] == 1){
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... |