# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90469 | xiaowuc1 | Bank (IZhO14_bank) | C++14 | 104 ms | 6376 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> matrix;
int n, m;
int val[20];
int bases[20];
vector<int> masks[1001];
void solve() {
cin >> n >> m;
{
vector<int> v, w;
v.resize(n);
for(int i = 0; i < n; i++) {
cin >> v[i];
}
w.resize(m);
for(int i = 0; i < m; i++) {
cin >> w[i];
}
sort(v.begin(), v.end());
sort(w.begin(), w.end());
int a = 0;
int b = 0;
while(a < v.size() && b < w.size()) {
if(v[a] == w[b]) {
v.erase(v.begin() + a);
w.erase(w.begin() + b);
}
else if(v[a] < w[b]) a++;
else b++;
}
n = v.size();
m = w.size();
for(int i = 0; i < n; i++) {
val[i] = v[i];
}
for(int i = 0; i < m; i++) {
bases[i] = w[i];
}
}
sort(val, val+n);
reverse(val, val+n);
for(int mask = 1; mask < (1<<m); mask++) {
int v = 0;
int t = mask;
while(v <= 1000 && t) {
v += bases[__builtin_ctz(t)];
t &= t-1;
}
if(v <= 1000) masks[v].push_back(mask);
}
unordered_set<int> ret;
ret.insert(0);
for(int i = 0; i < n; i++) {
unordered_set<int> nret;
for(int out2: ret) {
for(int out: masks[val[i]]) {
if(out&out2) continue;
if(__builtin_popcount(out | out2) + 2*(n-i-1) > m) continue;
nret.insert(out | out2);
}
}
ret = nret;
}
if(ret.empty()) cout << "NO\n";
else cout << "YES\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
solve();
}
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... |