# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676209 | murad_2005 | Bank (IZhO14_bank) | C++14 | 1092 ms | 12576 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>
#define ll long long
#define pii pair<int, int>
#define piii pair<pii, int>
#define pllll pair<ll, ll>
#define pb push_back
#define all(v) v.begin(), v.end()
#define size(v) v.size()
#define INF 2e18
#define f first
#define s second
using namespace std;
void solve(){
int n, m;
cin >> n >> m;
vector<int>a(n + 1), b(m + 1);
for(int i = 1; i <= n; ++i){
scanf("%d", &a[i]);
}for(int i = 1; i <= m; ++i){
scanf("%d", &b[i]);
}
vector<int>List[n + 1];
for(int mask = 1; mask < (1 << m); ++mask){
ll Total = 0;
for(int i = 0; i < m; ++i){
if(mask & (1 << i)){
Total += b[i + 1];
}
}
for(int i = 0; i < n; ++i){
if(Total == a[i + 1]){
List[i + 1].pb(mask);
}
}
}
vector<vector<int>>dp(n + 1, vector<int>(1 << m, 0));
for(int i = 1; i <= n; ++i){
for(int mask = 0; mask < (1 << m); ++mask){
dp[0][mask] = 1;
for(int j = 0; j < size(List[i]); ++j){
if((mask & List[i][j]) == List[i][j]){
dp[i][mask] = max(dp[i][mask], dp[i - 1][mask ^ List[i][j]]);
}
}
}
}
if(dp[n][(1 << m) - 1] == 1){
printf("%s\n", "YES");
}else{
printf("%s\n", "NO");
}
}
int main(){
int t;
t = 1;
//cin >> t;
while(t--){
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... |