Submission #171425

#TimeUsernameProblemLanguageResultExecution timeMemory
171425NightmarBank (IZhO14_bank)C++17
71 / 100
1070 ms1392 KiB
#include <iostream> #include <algorithm> #include <cmath> #include <string> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <iomanip> #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define ppb pop_back #define ft first #define sd second #define read freopen("input.txt", "r", stdin) #define write freopen("output.txt", "w", stdout) #define files read; write using namespace std; typedef long long ll; typedef pair<int, int> pii; const int Z = (int)2e3 + 228; const int N = (int)3e5 + 228; const int INF = (int)1e9 + 228; const int MOD = (int)1e9 + 7; const ll LLINF = (ll)1e15 + 228; bool f[20][1 << 21]; int main() { SWS; //files; int n, m; cin >> n >> m; vector<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]; for (int mask = 0; mask < (1 << m); mask++) { int sum = 0; for (int j = 0; j < m; j++) if ((mask >> j) & 1) sum += b[j]; if (sum == a[0]) f[0][mask] = true; } for (int i = 1; i < n; i++) for (int prev_mask = 0; prev_mask < (1 << m); prev_mask++) { if (!f[i - 1][prev_mask]) continue; for (int mask = 0; mask < (1 << m); mask++) { if ((prev_mask & mask) != prev_mask) continue; int sum = 0; for (int j = 0; j < m; j++) if (((mask >> j) & 1) && !((prev_mask >> j) & 1)) sum += b[j]; if (sum == a[i]) f[i][mask] = true; } } bool ans = false; for (int mask = 0; mask < (1 << m); mask++) ans |= f[n - 1][mask]; if (ans) cout << "YES"; else 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...