# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
854293 | WebbWayne | Bank (IZhO14_bank) | C++14 | 194 ms | 3276 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 <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, a, b) for(int i = a; i < b; i++)
#define vi vector<int>
#define ii pair<int, int>
#define pb push_back
#define f first
#define s second
#define all(i) (i).begin(), (i).end()
#define MOD 1000000007
#define endl '\n'
int n, m;
vector<vi> common;
vector<vector<bool>> visited;
void backtrack(int i, int state) {
if(i == n) {
cout<<"YES"<<endl;
exit(0);
}
if(visited[i][state]) return;
else visited[i][state] = true;
rep(j, 0, common[i].size()) {
int mask = common[i][j];
if(mask & state) continue;
backtrack(i+1, state | mask);
}
// return;
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(NULL);
cin>>n>>m;
vi nums(n);
vi bank(m);
common.resize(n);
visited.resize(n, vector<bool>(1<<m));
rep(i, 0, n)
cin>>nums[i];
rep(i, 0, m)
cin>>bank[i];
for(int mask = 0; mask < (1<<m); mask++) {
int sum = 0;
for(int i = 0; i < m; i++)
if(mask & (1<<i)) sum += bank[i];
for(int i = 0; i < n; i++)
if(sum == nums[i]) common[i].pb(mask); //this is a possible combination that could make my sum happen.
}
backtrack(0, 0);
cout<<"NO"<<endl;
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... |