# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1001472 | reginox | Bank (IZhO14_bank) | C++17 | 53 ms | 2540 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 ld long double
#define all(v) begin(v), end(v)
#define pi pair<int, int>
#define vi vector<int>
#define task "test"
using namespace std;
const int maxn = 20;
int n, m, a[maxn], b[maxn];
bool dp[maxn][1<<maxn];
vector<int> cnt[1005];
int main(){
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) cin >> b[i];
for(int i = 0; i < 1<<m; i++){
int sum = 0;
for(int j = 1; j <= m; j++){
if(i & (1<<j)) sum += b[j+1];
}
if(sum > 1000) continue;
for(int j = 1; j <= n; j++){
if(sum == a[j]) cnt[sum].push_back(j);
}
}
for(auto x:cnt[a[1]]){
dp[1][x] = true;
}
for(int j = 2; j <= n; j++){
for(auto x:cnt[a[j]]){
int t = x ^ ((1<<n)-1);
for(int sub = t; sub > 0; sub = (sub-1)&t){
dp[j][x^sub] |= dp[j-1][sub];
}
}
}
for(int i = 0; i < 1<<m; i++){
if(dp[n][i]){
cout << "YES";
return 0;
}
}
cout << "NO";
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... |