제출 #1035051

#제출 시각아이디문제언어결과실행 시간메모리
1035051Khanhcsp2은행 (IZhO14_bank)C++14
71 / 100
1035 ms10196 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[24], b[24], dp[24][1<<20]; vector<int> ms, ss[24]; 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]; for(int i=1;i<=n;i++) { for(int mask=1;mask<(1<<m);mask++) { int sum=0; for(int j=0;j<m;j++) if(mask>>j&1) sum+=b[j+1]; if(sum==a[i]) ss[i].push_back(mask); } } ms.push_back(0); dp[0][0]=1; for(int id=1;id<=n;id++) { vector<int> new_mask; for(int mask:ms) { for(int vl:ss[id]) { if((vl&mask)==0) dp[id][mask|vl]=1, new_mask.push_back(mask|vl); } } 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...