# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
656411 | asiat | Bank (IZhO14_bank) | C++14 | 668 ms | 81028 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 endl '\n'
using namespace std;
const int N = 21;
int dp[N][(1<<N)];
main(){
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
int m; cin >> m;
vector <int> v(n), g(m);
vector <int> can[n+1];
for (int i = 0; i < n; i++)cin >> v[i];
for (int i = 0; i < m; i++)cin >> g[i];
for (int i = 1; i < (1<<m); i++){
int sum = 0;
vector <int> ans;
int x = i;
while(x > 0){
ans.push_back(x&1);
x>>=1;
}
while(ans.size() < m)ans.push_back(0);
reverse(ans.begin(), ans.end());
cout << endl;
for (int j = 0; j < m; j++)
if(ans[j] == 1)sum+=g[j];
for (int j = 0; j < n; j++)
if(sum == v[j])can[j].push_back(i);
}
if(n > m){
cout << "NO";
return 0;
}
for (auto to : can[0]){
dp[0][to] = 1;
}
for (int i = 1; i < n; i++)
for (int mask = 1; mask < (1<<m); mask++){
if(!dp[i-1][mask])continue;
for (auto to : can[i])
if(!(mask & to))
dp[i][mask|to] |= dp[i-1][mask];
}
for (int i = 0; i < (1<<m); i++){
int to = dp[n-1][i];
if(to){
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
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... |