Submission #170412

#TimeUsernameProblemLanguageResultExecution timeMemory
170412div2derBank (IZhO14_bank)C++14
100 / 100
250 ms19292 KiB
#include <iostream> #include <vector> using namespace std; #define sz(s) (int)(s.size()) #define eb emplace_back const int N = 2e5 + 5; vector <int> v[N]; bool u[20][1 << 20]; int a[N], b[N]; void rec(int pos, int state, int n) { if (pos == n) { cout << "YES"; exit(0); } if (u[pos][state]) return; u[pos][state] = true; for (auto to : v[pos]) { if (state & to) continue; rec(pos + 1, state | to, n); } } int main () { int n, m; cin >> n >> m; for (int i = 0; i < n; ++ i) cin >> a[i]; for (int i = 0; i < m; ++ i) cin >> b[i]; for (int state = 0; state < (1 << m); ++ state) { int sum = 0; for (int i = 0; i < m; ++ i) if (state & (1 << i)) sum += b[i]; for (int i = 0; i < n; ++ i) if (sum == a[i]) v[i].eb(state); } rec(0, 0, n); 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...