# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
777728 | Sandarach151 | Bank (IZhO14_bank) | C++17 | 995 ms | 34928 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;
vector<int> states[20];
bool visited[20][1<<20];
bool ans[20][1<<20];
bool backtrack(int person, int curstate, int n){
if(person==n){
return true;
}
if(visited[person][curstate]){
return ans[person][curstate];
}
visited[person][curstate] = true;
bool res = false;
for(int i=0; i<states[person].size(); i++){
if((states[person][i] & curstate)==0){
res = res | backtrack(person+1, (states[person][i] | curstate), n);
if(res==true){
break;
}
}
}
ans[person][curstate]=res;
return res;
}
int main(){
int n, m;
cin >> n >> m;
int people[n];
int notes[m];
for(int i=0; i<n; i++){
cin >> people[i];
}
for(int i=0; i<m; i++){
cin >> notes[i];
}
for(int i=0; i<n; i++){
for(int curstate = 0; curstate < (1<<20); curstate++){
visited[i][curstate]=false;
}
}
for(int curstate = 0; curstate < (1<<20); curstate++){
int sum = 0;
for(int j=0; j<m; j++){
if((curstate & (1<<j))!=0){
sum+=notes[j];
}
}
for(int i=0; i<n; i++){
if(sum==people[i]){
states[i].push_back(curstate);
}
}
}
backtrack(0, 0, n) ? cout << "YES\n" : cout << "NO\n";
}
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... |