제출 #1098176

#제출 시각아이디문제언어결과실행 시간메모리
1098176vjudge1은행 (IZhO14_bank)C++17
71 / 100
1052 ms53580 KiB
#include "bits/stdc++.h" using namespace std; int n,m,a[20],b[20],used[20],was[(1 << 20)]; set <int> g[1001]; void rec(int mask){ if(was[mask]) return; was[mask] = 1; bool ok = 0; for(int i = 0 ; i < n ; i++){ if(!used[i]){ ok = 1; break; } } if(!ok){ cout << "YES"; exit(0); } for(int i = 0 ; i < n ; i++){ if(used[i]) continue; for(auto it : g[a[i]]){ if((mask & it)){ continue; } used[i] = 1; rec((mask | it)); used[i] = 0; } } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); 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 mask = 0 ; mask < (1 << m) ; mask++){ int sum = 0; for(int i = 0 ; i < m ; i++){ if(((mask >> i) & 1)){ sum += b[i]; } } if(sum <= 1000){ g[sum].insert(mask); } } rec(0); cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...