Submission #1133480

#TimeUsernameProblemLanguageResultExecution timeMemory
1133480domblyBank (IZhO14_bank)C++20
71 / 100
1095 ms3396 KiB
#include <bits/stdc++.h> #define int long long #define F first #define S second #define pb push_back using namespace std; const int N = 5000 + 10; const int inf = 1e15; const int mod = 1e9 + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin >> n >> m; vector<int>a(n),b(m); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; bool dp[n][1 << m]; for(int i = 0; i < n; i++) { for(int j = 0; j < (1 << m); j++) dp[i][j] = false; } for(int i = 0; i < n; i++) { for(int j = 0; j < (1 << m); j++) { int s = 0; for(int k = 0; k < m; k++) { if((1 << k) & j) s += b[k]; } if(s == a[i]) { vector<int>zeros; for(int k = 0; k < m; k++) { if((1 << k) & j) continue; zeros.pb(k); } int q = zeros.size(); if(i == 0) dp[i][j] = true; for(int msk = 0; msk < (1 << q); msk++) { int ss = 0; for(int aca = 0; aca < q; aca++) { if((1 << aca) & msk) ss += 1 << zeros[aca]; } if(i == 0) { dp[i][ss ^ j] = true; }else { dp[i][ss ^ j] |= dp[i - 1][ss]; } } } } } cout << (dp[n - 1][(1 << m) - 1] ? "YES" : "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...