Submission #115725

#TimeUsernameProblemLanguageResultExecution timeMemory
115725mrboorgerBank (IZhO14_bank)C++14
100 / 100
468 ms21048 KiB
#include <bits/stdc++.h> //#pragma optimize ("-Ofast") //#pragma comment (linker, "-STACK 99999999") #define ld long double #define ll long long #define F first #define S second #define pb push_back #define mp make_pair //#define int long long using namespace std; const int maxn = 22; int inf = 1e9 + 15; int a[maxn], b[maxn]; bool dp[maxn][1 << maxn]; vector <int> vc[20005]; //mask, count of pays int32_t main() { #ifdef LOCAL // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #else #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 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]; } if (n > m) { cout << "NO"; return 0; } for(int i = 0; i < (1 << m); i++) { int val = 0; for(int j = 0; j < m; j++) { if ((i & (1 << j)) > 0) { val += b[j]; } } vc[val].pb(i); } dp[0][0] = true; for(int i = 0; i < n; i++) for(int mask = 0; mask < (1 << m); mask++) { if (!dp[i][mask]) { continue; } for(auto j:vc[a[i]]) { if ((j & mask) == 0) { dp[i + 1][j | mask] = true; } } } bool f = false; for(int mask = 0; mask < (1 << m); mask++) { if (dp[n][mask]) { f = true; break; } } if (f) { cout << "YES"; } else { cout << "NO"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...