Submission #962971

#TimeUsernameProblemLanguageResultExecution timeMemory
962971raspyBank (IZhO14_bank)C++14
100 / 100
167 ms14552 KiB
#include <iostream> #include <vector> using namespace std; int a[25]; int b[25]; bool o[21][(1<<20)]; vector<int> gr[21]; void dfs(int n, int m, int ix, int ob) { if (ix == n) { cout << "YES\n"; exit(0); } if (o[ix][ob]) return; o[ix][ob] = true; for (auto pr : gr[ix]) if ((ob&pr) == 0) dfs(n, m, ix+1, ob|pr); return; } 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 op = 0; op < (1<<m); op++) { int vs = 0; for (int i = 0; i < m; i++) if ((1<<i)&op) vs += b[i]; for (int i = 0; i < n; i++) if (vs == a[i]) gr[i].push_back(op); } dfs(n, m, 0, 0); cout << "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...