Submission #337888

#TimeUsernameProblemLanguageResultExecution timeMemory
337888kutbilim_oneBank (IZhO14_bank)C++14
100 / 100
527 ms12012 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define all(x) x.begin(), x.end() #define int long long signed main(){ ios_base::sync_with_stdio(false); cin.tie(); int n, m; cin >> n >> m; vector<int> a(n), b(m); for(int i = 0; i < n; i++) cin >> a[i]; for(int j = 0; j < m; j++) cin >> b[j]; int maxx = *max_element(all(a)); vector<int> pass[1 + maxx]; for(int bin = 1; bin < (1 << m); bin++){ int i = 0, sum = 0, temp = bin; while(temp){ if(temp & 1) sum += b[i]; temp >>= 1; i++; } if(sum <= maxx) pass[sum].push_back(bin); } vector< vector<bool> > dp(n, vector<bool> (1 << m, false)); for(int i = 0; i < pass[a[0]].size(); i++){ dp[0][pass[a[0]][i]] = true; } for(int i = 1; i < n; i++){ int good = 0; for(int bin = 0; bin < (1 << m); bin++){ if(!dp[i-1][bin]) continue; for(auto last : pass[a[i]]) if(!(last & bin)) dp[i][last|bin] = good = true; } if(!good) break; } bool ans = false; for(int i = 0; !ans && i < (1 << m); i++){ if(dp[n-1][i]) ans = true; } if(ans) cout << "YES"; else cout << "NO"; return 0; }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:34:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0; i < pass[a[0]].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~
bank.cpp:43:51: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   43 |        if(!(last & bin)) dp[i][last|bin] = good = true;
      |                                                   ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...