# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95425 | choikiwon | Bank (IZhO14_bank) | C++17 | 210 ms | 8696 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;
int N, M;
int A[22], B[22], sum[1 << 20], dp[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 i = 1; i < N; i++) {
A[i] += A[i - 1];
}
for(int i = 0; i < (1 << M); i++) {
for(int j = 0; j < M; j++) {
if(i & (1 << j)) {
sum[i] += B[j];
}
}
}
for(int i = 0; i < (1 << M); i++) {
if(dp[i] == N) {
printf("YES");
return 0;
}
for(int j = 0; j < M; j++) {
if(i & (1 << j)) continue;
if(sum[i + (1 << j)] == A[ dp[i] ]) {
dp[i + (1 << j)] = max(dp[i + (1 << j)], dp[i] + 1);
}
else dp[i + (1 << j)] = max(dp[i + (1 << j)], dp[i]);
}
}
printf("NO");
}
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... |