# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
13510 | tncks0121 | Bank (IZhO14_bank) | C++14 | 74 ms | 596 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.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
const int Z = 20;
int N, M, A[Z], B[Z];
bool visited[Z][1 << Z];
vector<int> S[Z];
void backtrack(int i, int state) {
if (visited[i][state]) return;
visited[i][state] = true;
if (i == N) {
puts("YES");
exit(0);
}
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() {
scanf("%d%d", &N, &M);
for (int i = 0; i < N; i++) scanf("%d", A + i);
for (int j = 0; j < M; j++) scanf("%d", B + j);
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(sum);
}
backtrack(0, 0);
puts("NO");
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... |