# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636024 | a_aguilo | Bank (IZhO14_bank) | C++17 | 1093 ms | 12628 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vvi dp;
vvi possibilities;
//dp[i][j] = es posible satisfacer a los clientes i con j monedas
int main(){
int n, m;
cin >> n >> m;
int people[n];
int coins[m];
map<int, vi> coins_to_persons;
map<int, vi> persons_to_combs;
for (int i = 0; i < n; ++i) {
cin >> people[i];
if(coins_to_persons.find(people[i]) == coins_to_persons.end()) coins_to_persons[people[i]] = {i};
else coins_to_persons[people[i]].push_back(i);
}
//cout << " <" << endl;
for(int i = 0; i < m; ++i){
cin >> coins[i];
//cout << i << " " << coins[i] << endl;
}
//cout << " << " << endl;
dp = vvi(n+1, vi(1<<m, 0));
//cout << " a " << endl;
for(int i = 0; i < (1 << m); ++i){
//cout << "aa" << endl;
//cout << i << endl;
int ans = 0;
for(int j = 0; j < m; ++j){
if(i&(1 << j)) ans+= coins[j];
}
//cout << ans << endl;
for(int pers: coins_to_persons[ans]){
if(persons_to_combs.find(pers) == persons_to_combs.end()) persons_to_combs[pers] = {i};
else persons_to_combs[pers].push_back(i);
//cout << ans <<" " <<i << " " << pers << endl;
}
}
for(int i = 0; i < (1 << m); ++i) dp[0][i] = 1;
bool ans = false;
//cout << "a" << endl;
for(int who = 0; who < n; ++who){
for(int mask = 0; mask < (1 << m); ++mask){
for(int comb : persons_to_combs[who]){
if(mask & comb == comb) dp[who+1][mask] = max(dp[who+1][mask], dp[who][mask^comb]);
}
//cout << who << " " << mask << " " << dp[who+1][mask] << endl;
if(who == n-1 and dp[who+1][mask]) ans = true;
}
}
if(ans) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |