# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
727429 | josiftepe | Bank (IZhO14_bank) | C++14 | 41 ms | 82580 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 <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
vector<int> masks[maxn];
int salary[maxn];
int notes[maxn];
int dp[20][1 << 20];
int rec(int at, int bitmask) {
if(at == -1) {
return 1;
}
if(dp[at][bitmask] != -1) {
return dp[at][bitmask];
}
int result = 1;
for(int i = 0; i < masks[salary[at]].size(); i++) {
int tmp_mask = masks[salary[at]][i];
if((tmp_mask & bitmask) == tmp_mask) {
if(rec(at - 1, bitmask ^ tmp_mask)) {
return dp[at][bitmask] = 1;
}
}
}
return dp[at][bitmask] = 0;
}
int main() {
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++) {
cin >> salary[i];
}
for(int i = 0; i < m; i++) {
cin >> notes[i];
}
for(int bitmask = 0; bitmask < (1 << m); bitmask++) {
int sum = 0;
for(int i = 0; i < m; i++) {
if(bitmask & (1 << i)) {
sum += notes[i];
}
}
masks[sum].push_back(bitmask);
}
memset(dp, -1, sizeof dp);
cout << (rec(n - 1, (1 << m) - 1) == 1 ? "YES" : "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... |