Submission #1013050

#TimeUsernameProblemLanguageResultExecution timeMemory
1013050aufanBank (IZhO14_bank)C++17
71 / 100
1058 ms211604 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> b(m); for (int i = 0; i < m; i++) cin >> b[i]; vector<int> sum(1 << m); for (int i = 0; i < (1 << m); i++) { for (int j = 0; j < m; j++) { if (i >> j & 1) { sum[i] += b[j]; } } } vector<int> dp; dp.push_back(0); for (int i = 0; i < n; i++) { vector<int> ndp; for (int j = 0; j < (1 << m); j++) { if (sum[j] == a[i]) { for (auto mask : dp) { if ((j & mask) == 0) { ndp.push_back(j | mask); } } } } sort(ndp.begin(), ndp.end()); ndp.erase(unique(ndp.begin(), ndp.end()), ndp.end()); swap(dp, ndp); } cout << (!dp.empty() ? "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...