# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
340074 | emil_physmath | Bank (IZhO14_bank) | C++17 | 571 ms | 16320 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 <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
typedef double ldouble;
typedef long long llong;
typedef unsigned int uint;
vector<uint> sumup[1001];
int sum[1 << 20], bits[1 << 20];
bool ok[1 << 20];
bool IsSet(uint mask, uint i)
{
return mask & (1 << i);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int& x: a)
cin >> x;
vector<int> b(m);
for (int& x: b)
cin >> x;
for (uint mask = 0; mask < (1 << m); ++mask)
{
int curSum = 0, curBits = 0;
for (int i = 0; i < m; ++i)
if (IsSet(mask, i))
{
++curBits;
curSum += b[i];
}
if (curSum <= 1000)
sumup[curSum].push_back(mask);
sum[mask] = curSum;
bits[mask] = curBits;
}
vector<uint> possLeft;
possLeft.push_back((1 << m) - 1);
for (int i = 0; i < n; ++i)
{
for (uint mask = 0; mask < (1 << m); ++mask)
ok[mask] = false;
for (uint left: possLeft)
{
/*if ((1 << bits[left]) < sumup[a[i]].size())
{
for(uint mask = left; mask; mask = (mask - 1) & left)
if (sum[mask] == a[i])
ok[left ^ mask] = true;
}
else
{*/
for (uint mask: sumup[a[i]])
if ((mask & left) == mask)
ok[left ^ mask] = true;
//}
}
possLeft.clear();
for (uint mask = 0; mask < (1 << m); ++mask)
if (ok[mask])
possLeft.push_back(mask);
}
// cerr << possLeft.size() << endl;
cout << (possLeft.size() ? "YES" : "NO");
}
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... |