# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
869961 | TimAni | Bank (IZhO14_bank) | C++17 | 1068 ms | 79940 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 <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
#include <cmath>
#include <array>
using namespace std;
using ll = long long;
void setIO(string File_name) {
cin.tie(0)->sync_with_stdio(0);
if (File_name.size()) {
freopen((File_name + ".in").c_str(), "r", stdin);
freopen((File_name + ".out").c_str(), "w", stdout);
}
}
void sol() {
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
map<int, vector<int>> possible_sums;
for(int mask = 0; mask < (1 << m); mask++){
ll sum = 0;
for(int bit = 0; bit < m; bit++){
if(mask & (1ll << bit)){
sum += b[bit];
}
}
possible_sums[sum].push_back(mask);
}
vector<vector<bool>> dp(1 << m, vector<bool>(n + 1));
for(int mask = 0; mask < (1 << m); mask++){
dp[mask][0] = 1;
}
for(int i = 1; i <= n; i++){
int x = a[i - 1];
vector<int> possibilities = possible_sums[x];
for(auto el : possibilities){
for(int mask = 0; mask < (1 << m); mask++){
bool been = false;
for(int bit = 0; bit < m; bit++){
if((el & (1 << bit)) && (mask & (1 << bit))){
been = true;
break;
}
}
if(!been){
if(dp[mask][i - 1]){
dp[el | mask][i] = true;
}
}
}
}
}
for(int mask = 0; mask < (1 << m); mask++){
if(dp[mask][n]){
cout << "YES";
return;
}
}
cout << "NO";
}
int main() {
setIO("");
int T = 1;
//cin >> T;
while (T--) sol();
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... |