Submission #972814

#TimeUsernameProblemLanguageResultExecution timeMemory
972814saidponBank (IZhO14_bank)C++14
100 / 100
846 ms11092 KiB
#include <bits/stdc++.h> #define ordered_set tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define nemeshay ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define allr(pon) pon.rbegin(), pon.rend() #include <ext/pb_ds/assoc_container.hpp> #define all(pon) pon.begin(), pon.end() #include <ext/pb_ds/tree_policy.hpp> #define pii pair <int, int> #define nosolve puts("-1") #define YES puts("YES") #define pb push_back #define pf push_front #define int long long #define OK puts("OK") #define NO puts("NO") #define sigma signed #define sc second #define fr first using namespace __gnu_pbds; using namespace std; const int N = 1048576, INF = 2e9 + 7; int a[N], b[N], dp[N]; vector <int> pon[30]; sigma main(){ nemeshay int n, m; 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 l = 0; l < (1 << m); l++){ int sum = 0; for (int j = 0; j < m; j++){ if (l & (1 << j)) sum += b[j]; } for (int i = 0; i < n; i++) if (sum == a[i]) pon[i].pb(l); } for (int i = 1; i < N; i++) dp[i] = -1; for (int i = 0; i < n; i++){ for (int l = (1 << m) - 1; l >= 0; l--){ if (dp[l] != -1){ for (auto j: pon[i]){ if (!(l & j)){ dp[l | j] = dp[l] + 1; } if (dp[l | j] == n){ YES; return 0; } } } } } NO; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...