Submission #1292378

#TimeUsernameProblemLanguageResultExecution timeMemory
1292378kamBank (IZhO14_bank)C++20
71 / 100
1096 ms8236 KiB
#include<unordered_map> #include<unordered_set> #include<algorithm> #include<iostream> #include<cstdlib> #include<iomanip> #include<cstring> #include<cassert> #include<numeric> #include<vector> #include<string> #include<chrono> #include<random> #include<stack> #include<queue> #include<cmath> #include<set> #include<map> #include<ios> using namespace std; int n, m; vector<int>a, b; vector<vector<int>>gp; bool dfs(int id, int vis) { if (id == n) return true; for (int& x : gp[a[id]]) { if ((vis ^ x) == (vis | x)) { if (dfs(id + 1, vis | x)) return true; } } return false; } void solve() { cin >> n >> m; a = vector<int>(n); b = vector<int>(m); gp = vector<vector<int>>(2e4 + 1); for (int i = 0; i < n; i++) cin >> a[i]; for (int j = 0; j < m; j++) cin >> b[j]; for (int i = 0; i < (1 << m); i++) { int sum = 0; for (int j = 0; j < m; j++) { if ((1 << j) & i) sum += b[j]; } gp[sum].push_back(i); } cout << (dfs(0, 0) ? "YES" : "NO"); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("bank.in", "r", stdin); //freopen("bank.out", "w", stdout); //signed _; cin >> _; while (_--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...