Submission #914615

#TimeUsernameProblemLanguageResultExecution timeMemory
914615DAleksaBank (IZhO14_bank)C++17
71 / 100
1050 ms3408 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; int a[n], b[m]; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; sort(a, a + n); reverse(a, a + n); vector<int> masks[n]; for(int mask = 0; mask < (1 << m); mask++) { int sum = 0; for(int j = 0; j < m; j++) if((1 << j) & mask) sum += b[j]; for(int i = 0; i < n; i++) if(sum == a[i]) masks[i].push_back(mask); } bool dp[n][1 << m]; for(int i = 0; i < n; i++) for(int j = 0; j < (1 << m); j++) dp[i][j] = false; for(int i : masks[0]) dp[0][i] = true; for(int i = 1; i < n; i++) { for(int mask = 0; mask < (1 << m); mask++) { for(int mask2 : masks[i]) { if((mask | mask2) == mask && dp[i - 1][mask ^ mask2]) { dp[i][mask] = true; break; } } } } for(int i = 0; i < (1 << m); i++) { if(dp[n - 1][i]) { cout << "YES"; return 0; } } cout << "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...