제출 #1035063

#제출 시각아이디문제언어결과실행 시간메모리
1035063Khanhcsp2은행 (IZhO14_bank)C++14
71 / 100
1036 ms37328 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<<21]; vector<int> ms, ss[N]; 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 mask=1;mask<(1<<m);mask++) { int sum=0; for(int j=0;j<m;j++) if(mask>>j&1) sum+=b[j+1]; ss[sum].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[a[id]]) { if((vl&mask)==0) dp[id][mask|vl]=1, new_mask.push_back(mask|vl); } } if(new_mask.size()==0) { cout << "NO"; return; } 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...