Submission #1035055

#TimeUsernameProblemLanguageResultExecution timeMemory
1035055Khanhcsp2Bank (IZhO14_bank)C++14
71 / 100
1031 ms17344 KiB
#include<bits/stdc++.h> #define el '\n' #define fi first #define sc second #define int ll #define pii pair<int, int> #define all(v) v.begin(), v.end() using namespace std; using ll=long long; using ull=unsigned long long; using ld=long double; const int mod=1e9+7; const int N=1e5+11; int n, m, a[N], b[N], dp[21][1<<20]; vector<int> ms; void sol() { cin >> n >> m; for(int i=1;i<=n;i++) cin >> a[i]; for(int i=1;i<=m;i++) cin >> b[i]; ms.push_back(0); dp[0][0]=1; for(int id=1;id<=n;id++) { vector<int> new_mask; for(int mask:ms) { vector<int> bit; for(int i=0;i<m;i++) if(!(mask>>i&1)) bit.push_back(i); int sz=bit.size(); for(int i=1;i<(1<<sz);i++) { int ss=0, sum=0; for(int j=0;j<sz;j++) if(i>>j&1) ss+=(1<<bit[j]), sum+=b[bit[j]+1]; if(sum==a[id]) dp[id][mask|ss]=1, new_mask.push_back(mask|ss); } } sort(all(new_mask)); new_mask.erase(unique(all(new_mask)), new_mask.end()); ms=new_mask; } int ch=0; for(int i=0;i<(1<<m);i++) if(dp[n][i]) ch=1; if(ch==1) cout << "YES"; else cout << "NO"; } signed main() { // freopen("divisor.INP", "r", stdin); // freopen("divisor.OUT", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); int t=1; //cin >> t; while(t--) { sol(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...