# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073227 | vjudge1 | Bank (IZhO14_bank) | C++17 | 2 ms | 348 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;
const int Z = 20;
int N, M, A[Z], B[Z];
bool visited[Z][1 << Z];
vector<int> S[Z];
bool ans = false;
void backtrack(int i, int state) {
if (i == N) {
ans = true;
return;
}
if (visited[i][state]) return;
visited[i][state] = true;
for (int e = 0; e < S[i].size(); e++) {
int s = S[i][e];
if (state & s) continue;
backtrack(i + 1, state | s);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
freopen("bank.in","r",stdin);
freopen("bank.out","w",stdout);
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 state = 0; state < (1 << M); state++) {
int sum = 0;
for (int i = 0; i < M; i++) if (state & (1 << i)) sum += B[i];
for (int i = 0; i < N; i++) if (sum == A[i]) S[i].push_back(state);
}
backtrack(0, 0);
if (ans) cout << "YES\n";
else cout << "NO\n";
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... |