Submission #1092014

#TimeUsernameProblemLanguageResultExecution timeMemory
1092014juicyBank (IZhO14_bank)C++17
100 / 100
132 ms4564 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> a(n), b(m); for (int i = 0; i < n; ++i) { cin >> a[i]; } partial_sum(a.begin(), a.end(), a.begin()); for (int i = 0; i < m; ++i) { cin >> b[i]; } vector<int> dp(1 << m, 0); for (int mask = 1; mask < (1 << m); ++mask) { int sum = 0; for (int i = 0; i < m; ++i) { if (mask >> i & 1) { sum += b[i]; } } for (int i = 0; i < m; ++i) { if (mask >> i & 1) { int j = mask ^ (1 << i); dp[mask] = max(dp[mask], dp[j] + (dp[j] ^ n && sum == a[dp[j]])); } } } cout << (dp.back() == n ? "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...