Submission #246525

#TimeUsernameProblemLanguageResultExecution timeMemory
246525aloo123Bank (IZhO14_bank)C++14
19 / 100
119 ms45816 KiB
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <ratio> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <climits> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/trie_policy.hpp> #define ll long long #define ld long double #define mp make_pair #define pb push_back #define in insert #define vll vector<ll> #define endl "\n" #define pll pair<ll,ll> #define f first #define s second #define int ll #define sz(x) (ll)x.size() #define all(x) (x.begin(),x.end()) using namespace std; // using namespace __gnu_pbds; // typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os; const ll INF = 1e12; const ll N =(22); // TODO : change value as per problem const ll MOD = 1e9+7; ll a[N]; ll b[N]; vll nice[N]; bool dp[N][(1ll<<22) + 5]; bool vis[N][(1ll<<22) + 5]; ll n,m; bool recurse(ll i,ll j){ if(i > n) return 1; if(vis[i][j]) return dp[i][j]; bool ans = 0; for(auto k:nice[i]){ if((j&k) == j){ ans |= recurse(i+1,j^k); } } vis[i][j] =1; return dp[i][j] = ans; } void solve(){ cin >> n >> m; for(int i = 1;i<=n;i++) cin >> a[i]; for(int i= 1;i<=m;i++) cin >> b[i]; sort(a+1,a+n+1); for(int i =1;i<=n;i++){ ll sum = a[i]; for(int j = 0;j<(1ll<<m);j++){ ll cur = 0; string bin; for(int k =0;k<m;k++){ if((j&(1ll<<k))){ cur += b[k+1]; } } if(cur == sum) { nice[i].pb(j); } } } for(int i =0;i<22;i++){ for(int j= 0;j<(1ll<<21);j++) vis[i][j] = false; } bool gg = recurse(1,0); if(gg) cout << "YES\n"; else cout << "NO\n"; // cout << recurse(1,0) << endl; // cout << ans << endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); ll tt=1; while(tt--){ 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...