Submission #337735

#TimeUsernameProblemLanguageResultExecution timeMemory
337735BY_KUTBILIMBank (IZhO14_bank)C++14
100 / 100
540 ms8780 KiB
/** @BY_KUTBILIM **/ #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).end() int main(){ ios_base::sync_with_stdio(false); cin.tie(); int n, m; cin >> n >> m; vector<vector<bool>> dp(n, vector<bool>((1 << m), false)); int a[n], b[m]; for(int i = 0; i < n; i++)cin >> a[i]; for(int i = 0; i < m; i++)cin >> b[i]; vector<vector<int>> can(1001); for(int mask = 0; mask < (1 << m); mask++){ int sum = 0; for(int i = 0; i < m; i++){ if((1 << i) & mask)sum += b[i]; } if(sum <= 1000){ can[sum].pb(mask); } } for(auto mask : can[a[0]])dp[0][mask] = true; for(int i = 1; i < n; i++){ bool find = false; for(int mask = 0; mask < (1 << m); mask++){ if(!dp[i-1][mask])continue; for(auto j : can[a[i]]){ if((mask & j) == 0){ dp[i][mask|j] = true; find = true; } } } if(!find)break; } bool ok = false; for(int mask = 0; mask < (1 << m); mask++){ if(dp[n-1][mask])ok = true; } if(ok)cout << "YES\n"; else 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...