제출 #1292404

#제출 시각아이디문제언어결과실행 시간메모리
1292404kam은행 (IZhO14_bank)C++20
71 / 100
1096 ms12576 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, f = 0; vector<int>a, b; vector<vector<int>>gp; void dfs(int id, int vis) { if (id == n) { f = 1; return; } for (int& x : gp[a[id]]) { if ((vis ^ x) == (vis | x)) { dfs(id + 1, vis | x); if (f) return; } } } void solve() { cin >> n >> m; a = vector<int>(n); b = vector<int>(m); gp = vector<vector<int>>(2e5 + 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); } dfs(0, 0); cout << (f ? "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...