Submission #1127551

#TimeUsernameProblemLanguageResultExecution timeMemory
1127551woohyun_jngBank (IZhO14_bank)C++20
71 / 100
1090 ms25084 KiB
#include <bits/stdc++.h> #define int long long #define MAX 21 using namespace std; int A[MAX], B[MAX], dp[2][1 << MAX], val[1 << MAX], res[MAX]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int N, M; cin >> N >> M; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 0; i < M; i++) cin >> B[i]; for (int i = 0; i < (1 << M); i++) for (int j = 0; j < M; j++) if (i & (1 << j)) val[i] += B[j]; for (int i = 1; i <= N; i++) { fill(dp[i & 1], dp[i & 1] + (1 << M), 30000); for (int j = 0; j < (1 << M); j++) { if (val[j] - dp[i & 1 ^ 1][j] == A[i]) { dp[i & 1][j] = val[j], res[i] = 1; for (int k = 0; k < M; k++) if (!(j & (1 << k))) dp[i & 1][j | (1 << k)] = val[j]; } for (int k = 0; k < M; k++) if (!(j & (1 << k))) dp[i & 1][j | (1 << k)] = min(dp[i & 1][j | (1 << k)], dp[i & 1][j]); } } cout << (res[N] ? "YES" : "NO") << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...