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;
int N, M;
vector<int> salaries;
vector<int> bankNotes;
vector<int> params;
int LSOne(int a) {
return a & (-a);
}
bool canDo = false;
void bitmask(int ind, vector<int> ¶ms) {
if (ind == M) {
// checker
for (int i = 0; i < N; i++) {
// cout << i << ": ";
int iBitmask = params[i];
int currSum = 0;
while (iBitmask) {
int currInd = __builtin_ctz(LSOne(iBitmask));
// cout << currInd << ", ";
currSum += bankNotes[currInd];
iBitmask -= LSOne(iBitmask);
}
// cout << "\n";
if (currSum != salaries[i]) return;
}
cout << "YES\n";
exit(0);
} else {
for (int i = 0; i < N; i++) {
params[i] |= (1 << ind);
bitmask(ind+1, params);
params[i] ^= (1 << ind);
}
bitmask(ind+1, params);
}
}
int main() {
cin >> N >> M;
salaries.resize(N);
params.resize(N, 0);
for (int i = 0; i < N; i++) {
cin >> salaries[i];
}
bankNotes.resize(M);
for (int i = 0; i < M; i++) {
cin >> bankNotes[i];
}
bitmask(0, params);
cout << "NO\n";
}
# | 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... |