Submission #331532

#TimeUsernameProblemLanguageResultExecution timeMemory
331532jovan_bBank (IZhO14_bank)C++17
52 / 100
84 ms14956 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; vector <int> maske[20005]; int dp[1000005]; int dpp[1000005]; int a[25]; int b[25]; int main(){ ios_base::sync_with_stdio(false); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; for(int i=1; i<=n; i++){ cin >> a[i]; } for(int j=0; j<m; j++){ cin >> b[j]; } for(int mask=1; mask<(1<<m); mask++){ int sum = 0; for(int j=0; j<m; j++){ if((1<<j)&mask) sum += b[j]; } maske[sum].push_back(mask); } dpp[0] = 1; for(int i=0; i<n; i++){ for(int mask=0; mask<(1<<m); mask++){ if(!dpp[mask]) continue; for(auto c : maske[a[i+1]]){ if(!(c&mask)) dp[mask|c] = 1; } } for(int mask=0; mask<(1<<m); mask++){ dpp[mask] = dp[mask]; dp[mask] = 0; } } for(int i=0; i<(1<<m); i++){ if(dpp[i]){ cout << "YES\n"; return 0; } } cout << "NO\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...