# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
5017 | tncks0121 | Bank (IZhO14_bank) | C++98 | 69 ms | 2496 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;
int N, M, A[20], B[20];
bool S[20][1<<20];
bool Table[20][1<<20];
int main() {
scanf("%d%d", &N, &M);
for(int i = 0; i < N; i++) scanf("%d", A+i);
for(int i = 0; i < M; i++) scanf("%d", 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(A[i] == sum) S[i][state] = 1;
}
// Table[i][state]: A[1..i] 지불, 현재 state만큼의 수표 사용
for(int state = 0; state < (1<<M); state++) Table[0][state] = S[0][state];
for(int i = 1; i < N; i++) {
for(int state = 0; state < (1<<M); state++) {
for(int p = 0; p < (1<<M) && Table[i][state]; p++) {
if(S[i][p] && ((p & state) == p) && Table[i-1][p^state]) Table[i][state] = 1;
}
}
}
for(int state = 0; state < (1<<M); state++) if(Table[N-1][state]) return puts("YES"), 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... |