Submission #631012

#TimeUsernameProblemLanguageResultExecution timeMemory
631012ojoConmigoBank (IZhO14_bank)C++17
100 / 100
387 ms4564 KiB
#include <bits/stdc++.h> using namespace std; int n,m; vector<int> a,b,dp; vector<vector<int>> masks; bool f(int i, int mask){ if(i == n)return true; if(dp[mask] != -1) return dp[mask]; for(int newMask : masks[i]){ if((mask&newMask) != 0) continue; if(f(i+1,mask|newMask)){ dp[mask] = 1; dp[mask|newMask] = 1; return true; } } dp[mask] = 0; return false; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; a.resize(n); b.resize(m); masks.resize(n); dp.assign(1<<m,-1); for(int i=0; i<n; i++){ cin >> a[i]; } for(int i=0; i<m; i++){ cin >> b[i]; } for(int i=0; i<n; i++){ for(int mask = 1; mask < (1<<m); mask++){ int suma = 0; for(int j=0; j<m; j++){ if(mask&(1<<j)){ suma += b[j]; if(suma > a[i])break; } } if(suma == a[i]){ masks[i].push_back(mask); } } } if(f(0,0)){ cout << "YES\n"; }else cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...