# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093898 | InvMOD | Bank (IZhO14_bank) | C++14 | 76 ms | 8640 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;
template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
const int N = 20;
int n, m, a[N], b[N];
int dp[(1<<N)], knapsack[(1<<N)];
void solve()
{
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
dp[0] = 1;
for(int mask = 0; mask < (1<<m); mask++){
if(!dp[mask]) continue;
//can go through all permutation that form cur mask
int cur_wanted = a[dp[mask]-1];
for(int i = 0; i < m; i++){
if(mask>>i&1) continue;
int new_mask = mask | (1<<i);
if(knapsack[mask] + b[i] == cur_wanted){
if(ckmx(dp[new_mask], dp[mask]+1)){
knapsack[new_mask] = 0;
}
}
else{
if(ckmx(dp[new_mask], dp[mask])){
knapsack[new_mask] = knapsack[mask] + b[i];
}
}
}
}
cout << (dp[(1<<m)-1] == n+1 ? "YES" : "NO") <<"\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
solve();
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... |