Submission #406528

#TimeUsernameProblemLanguageResultExecution timeMemory
406528CrouchingDragonBank (IZhO14_bank)C++17
100 / 100
482 ms4840 KiB
#include "bits/stdc++.h" using namespace std; #define endl '\n' #define debug(x) cerr << #x << " == " << (x) << '\n'; #define all(x) begin(x), end(x) using ll = long long; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N, M; cin >> N >> M; vector<int> a(N), b(M); for (auto& x : a) cin >> x; for (auto& x : b) cin >> x; vector<int> sum(1 << M); vector<vector<int>> E(N); for (int j = 0; j < M; ++j) sum[1 << j] = b[j]; for (int mask = 1; mask < (1 << M); ++mask) { int lsb = mask & -mask; sum[mask] = sum[mask ^ lsb] + sum[lsb]; for (int i = 0; i < N; ++i) { if (sum[mask] == a[i]) E[i].push_back(mask); } } vector<bool> dp(1 << M, false), dpnxt(1 << M, false); dp[0] = true; for (int i = 0; i < N; ++i) { for (int mask = 0; mask < (1 << M); ++mask) { if (not dp[mask]) continue; for (auto add : E[i]) { if (mask & add) continue; dpnxt[mask | add] = true; } } fill(all(dp), false), swap(dp, dpnxt); } string ans = count(all(dp), true) ? "YES" : "NO"; cout << ans << endl; exit(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...