Submission #1071897

#TimeUsernameProblemLanguageResultExecution timeMemory
1071897horezusholBank (IZhO14_bank)C++14
71 / 100
1044 ms12800 KiB
#include<bits/stdc++.h> #define F first #define S second #define SZ(x) int((x).size()) const char nl = '\n'; using ll = long long; using namespace std; const int N = 20; bool dp[N][(1 << N)]; int sum[(1 << N)]; int n, m; int a[N], b[N]; void verkefni() { cin >> n >> m; for (int i = 0; i < n; i ++) cin >> a[i]; for (int j = 0; j < m; j ++) cin >> b[j]; for (int mask = 0; mask < (1 << m); mask ++) { int cur = 0; for (int i = 0; i < m; i ++) { if (mask & (1 << i)) { cur += b[i]; } } sum[mask] = cur; } for (int mask = 0; mask < (1 << m); mask ++) { // i = 0 if (sum[mask] == a[0]) { dp[0][mask] = true; } } for (int i = 0; i < n-1; i ++) { for (int mask = 0; mask < (1 << m); mask ++) { if (!dp[i][mask]) continue; for (int cur = 0; cur < (1 << m); cur ++) { if (mask <= cur && (mask & cur) == mask) { if (sum[cur] - sum[mask] == a[i+1]) { // cout << sum[cur] << " " << sum[mask] << " " << b[i+1] << nl; dp[i+1][cur] = true; } } } } } // cout << nl; for (int mask = 0; mask < (1 << m); mask ++) { if (dp[n-1][mask]) { cout << "YES"; return ; } } cout << "NO"; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tst = 1; // cin >> tst; while (tst --) { verkefni(); cout << nl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...