# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
837474 | uped | Bank (IZhO14_bank) | C++14 | 1062 ms | 11220 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;
using ll = long long;
vector<ll> sieve(ll n) {
vector<bool> is_prime(n + 1, true);
is_prime[0] = is_prime[1] = false;
for (ll i = 2; i <= n; i++) {
if (is_prime[i] && (long long) i * i <= n) {
for (ll j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
vector<ll> primes;
for (ll i = 2; i <= n; ++i) {
if (is_prime[i]) {
primes.push_back(i);
}
}
return primes;
}
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
void fileio(const string &name) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> b(m);
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
vector<vector<uint32_t>> masks(1001);
vector<int> dp1(1 << m);
for (uint32_t i = 1; i < (1 << m); ++i) {
for (int j = 0; j < m; ++j) {
if (i & (1 << j)) {
dp1[i] = dp1[i ^ (1 << j)] + b[j];
if (dp1[i] <= 1000) {
masks[dp1[i]].push_back(i);
}
break;
}
}
}
// for (int i = 0; i < 20; ++i) {
// cout << i << ": ";
// for (int j = 0; j < masks[i].size(); ++j) {
// cout << bitset<10>(masks[i][j]) << ' ';
// }
// cout << '\n';
// }
vector<bool> dp2(1 << m, true);
for (int i = 0; i < n; ++i) {
auto& vm = masks[a[i]];
for (int k = 0; k < (1 << m); ++k) {
if (!dp2[k]) continue;
bool match = false;
for (int j = 0; j < vm.size(); ++j) {
if ((k ^ vm[j]) == 0) {
match = true;
}
}
dp2[k] = match;
}
}
// for (int i = 0; i < 50; ++i) {
// cout << bitset<10>(i) << ' ' << dp2[i] << '\n';
// }
for (int i = 0; i < (1 << m); ++i) {
if (dp2[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... |