# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
362743 | sumit_kk10 | Bank (IZhO14_bank) | C++14 | 766 ms | 202348 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 fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e6 + 2;
vector<long long int> pos[N];
int n, m, a[N], b[N];
bool vis[N];
long long dp[20][(1LL << 20) + 1];
bool go(int i, long long mask){
if(i == n)
return true;
if(dp[i][mask] != -1)
return dp[i][mask];
bool ans = false;
for(auto k : pos[a[i]]){
if((mask & k) != 0)
continue;
ans = (ans | go(i + 1, (mask | k)));
}
return dp[i][mask] = ans;
}
void solve() {
memset(dp, -1, sizeof dp);
cin >> n >> m;
for(int i = 0; i < n; ++i)
cin >> a[i];
for(int i = 0; i < m; ++i)
cin >> b[i];
for(int mask = 0; mask < (1LL << m); ++mask){
long long sum = 0;
for(int j = 0; j < m; ++j)
if(mask & (1LL << j))
sum += b[j];
pos[sum].push_back(mask);
}
cout << (go(0, 0) ? "YES\n" : "NO\n");
}
int main() {
fast;
int 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... |