Submission #1035072

#TimeUsernameProblemLanguageResultExecution timeMemory
1035072Khanhcsp2Bank (IZhO14_bank)C++14
100 / 100
170 ms58192 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> ss[N]; void dpp(int id, int mask) { if(id==n+1) { cout << "YES"; exit(0); } if(dp[id][mask]) return; dp[id][mask]=1; for(int ms:ss[a[id]]) if((ms&mask)==0) dpp(id+1, mask|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]; 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); } dpp(1, 0); 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...