# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
432167 | jli12345 | Bank (IZhO14_bank) | C++14 | 93 ms | 8516 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;
void fastIO(){
ios_base::sync_with_stdio(false);
cin.tie(0);
}
int N, M;
int b[21], a[21];
pair<int, int> dp[(1<<20)];
int main(){
//fastIO();
cin >> N >> M;
for (int i = 1; i <= N; i++)
cin >> b[i];
for (int i = 1; i <= M; i++){
cin >> a[i];
}
bool work = false;
memset(dp, -1, sizeof(dp));
dp[0] = {0, 0};
for (int i = 1; i < (1<<M); i++){
for (int j = 0; j < M; j++){
if (i&(1<<j)){
if (dp[i^(1<<j)].first > dp[i].first){
dp[i].first = dp[i^(1<<j)].first;
dp[i].second = dp[i^(1<<j)].second + a[j+1];
if (dp[i].second == b[dp[i].first+1]){
dp[i].second = 0;
dp[i].first++;
}
}
}
}
if (dp[i].first == N){
work = true;
break;
}
}
if (work)
cout << "YES\n";
else
cout << "NO\n";
}
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... |