Submission #1089191

#TimeUsernameProblemLanguageResultExecution timeMemory
1089191vjudge1Bank (IZhO14_bank)C++17
0 / 100
1 ms348 KiB
//don't copy pls) /*TAAK ZDES NADO RECURSIU PISAT*/ //I'm not in the danger i am the DANGER #include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> #define ll long long #define pb push_back #define int long long #define F first #define S second #define all(x) (x).begin(), (x).end() #define pii pair<int,int> #define sigma signed using namespace std; using namespace __gnu_pbds; const int N = 1e3 + 5; int mod = 1e9 + 7; const int INF = 1e18; int n,m,a[N],b[N],used[N]; set <int> st; int rec(int last = 0){ if(last == n) return 1; last++; int x = a[last]; int ans = 0; int mm = st.size(); for(int mask = 0 ; mask < (1 << mm) ; mask++){ if(ans) break; int sum = 0; int i = 0; i = 0; for(auto it : st){ if(((mask >> i) & 1)){ sum += it; } i++; } if(sum == x){ i = 0; vector <int> q; for(auto it : st){ if(((mask >> i) & 1)){ q.pb(it); } i++; } for(auto it : q){ st.erase(st.find(it)); } ans = max(ans , rec(last)); i = 0; q.clear(); for(auto it : st){ if(((mask >> i) & 1)){ q.pb(it); } i++; } for(auto it : q){ st.insert(it); } } } last--; return ans; } void Gold(){ cin >> n >> m; for(int i = 1 ; i <= n ; i++){ cin >> a[i]; } for(int i = 1 ; i <= m ; i++){ cin >> b[i]; st.insert(i); } int ans = rec(); if(ans){ cout << "YES\n"; return; } cout << "NO"; } sigma main(){ //freopen("txt.in","r",stdin); //freopen("txt.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); srand(time(0)); int TT = 1; // cin >> TT; for(int i = 1 ; i <= TT ; i++){ //cout << "Case " << i << ": "; Gold(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...