Submission #1077956

#TimeUsernameProblemLanguageResultExecution timeMemory
1077956MyCodeBank (IZhO14_bank)C++17
100 / 100
113 ms8788 KiB
#include <bits/stdc++.h> using namespace std; int sum[(1 << 20)], dp[(1 << 20)]; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int n, m; cin >> n >> m; int a[n], b[m], pref[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) pref[i] = a[i] + (i > 0 ? pref[i - 1] : 0); for (int i = 0; i < m; i++) cin >> b[i]; for (int mask = 0; mask < (1 << m); mask++) { sum[mask] = 0; for (int bit = 0; bit < m; bit++) sum[mask] += ((mask >> bit) & 1) * b[bit]; } for (int mask = 0; mask < (1 << m); mask++) { dp[mask] = -1; for (int bit = 0; bit < m; bit++) { if (((mask >> bit) & 1) == 1) dp[mask] = max(dp[mask], dp[mask - (1 << bit)]); } int i = 0; while (i < n && pref[i] != sum[mask]) i++; if (i == n) continue; if (i == 0) { dp[mask] = 0; continue; } for (int bit = 0; bit < m; bit++) { if (((mask >> bit) & 1) == 1 && dp[mask - (1 << bit)] != -1) { int left = sum[mask - (1 << bit)] - pref[dp[mask - (1 << bit)]] + b[bit]; if (left == a[i]) { dp[mask] = i; break; } } } } cout << (dp[(1 << m) - 1] == n - 1 ? "YES" : "NO"); 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...