# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731725 | Juan | Bank (IZhO14_bank) | C++17 | 1072 ms | 588 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;
//#pragma GCC optimize(03)
// #define int long long
#define pii pair<int, int>
#define ff first
#define ss second
const int maxn = 22;
int sal[maxn], notes[maxn];
bool dp[maxn][1<<(maxn-1)];
int32_t main(){
ios::sync_with_stdio(false);
int n, m; cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> sal[i];
for(int i = 0; i < m; i++) cin >> notes[i];
dp[0][0] = true;
for(int i = 1; i <= n; i++){
// p cada mask de notas
for(int mask = 0; mask < (1<<m); mask++){
vector<int> aux;
for(int e = 0; e < m; e++) if(mask & (1<<e)) aux.push_back(e);
// checar, entre as submasks, quais formam salario valido
// p sal[i] e se a submask restante eh valida p anterior
for(int submask = 0; submask < (1<<aux.size()); submask++){
int submask_val=0, val=0;
for(int e = 0; e < aux.size(); e++) if(submask & (1<<e)) val+=notes[aux[e]], submask_val += (1<<(aux[e]));
if(val==sal[i] && dp[i-1][mask^submask_val]) dp[i][mask] = true;
}
}
}
bool found = false;
for(int i = 0; i < (1<<m); i++) if(dp[n][i]) {cout << "YES\n"; found = true; break;}
if(found==false) cout << "NO\n";
}
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... |