# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
671464 | 2022-12-13T05:38:03 Z | Alihan_8 | Bank (IZhO14_bank) | C++17 | 2 ms | 1364 KB |
#include <bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} //#define int long long signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector <int> a(n), b(m); for ( auto &i: a ) cin >> i; for ( auto &i: b ) cin >> i; vector <int> g[n]; for ( int mask = 1; mask < (1 << m); mask++ ){ int cnt = 0; for ( int i = 0; i < m; i++ ){ if ( mask >> i & 1 ) cnt += b[i]; } for ( int j = 0; j < n; j++ ){ if ( a[j] == cnt ) g[j].pb(mask); } } for ( auto i: g ){ if ( i.empty() ){ cout << "NO\n"; return 0; } } const int S = 1 << m; vector <vector<int>> dp(n+1, vector <int> (S)), used(n+1, vector <int> (S)); function <int(int,int)> dfs = [&](int mask, int pos){ if ( pos == n ) return 1; if ( used[pos][mask] ) return dp[pos][mask]; used[pos][mask] = 1; int &res = dp[pos][mask]; for ( auto val: g[pos] ){ if ( (val & mask) ^ val ) continue; if ( dfs(mask^val, pos+1) ) res = 1; } return res; }; dfs(S-1, 0); if ( *max_element(all(dp[n])) ) cout << "YES"; else cout << "NO"; cout << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 1364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |