Submission #1107619

#TimeUsernameProblemLanguageResultExecution timeMemory
1107619julia_08Bank (IZhO14_bank)C++17
52 / 100
1100 ms8908 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 21; int a[MAXN], b[MAXN]; int dp[1 << MAXN], sum[1 << MAXN]; vector<int> v[MAXN]; int main(){ cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; for(int i=0; i<n; i++){ cin >> a[i]; } for(int i=0; i<m; i++){ cin >> b[i]; } for(int s=1; s<(1 << m); s++){ int bit = __builtin_ctz(s); sum[s] = sum[s ^ (1 << bit)] + b[bit]; } for(int i=0; i<n; i++){ for(int s=0; s<(1 << m); s++){ if(sum[s] == a[i]) v[i].push_back(s); } } for(int s=0; s<(1 << m); s++){ int i = min(n, dp[s] + 1); for(auto x : v[i - 1]){ if((x & s) == 0){ dp[s ^ x] = max(dp[s ^ x], i); } } } cout << (dp[(1 << m) - 1] == 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...