# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
171996 | emil_physmath | Bank (IZhO14_bank) | C++17 | 1048 ms | 9368 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 <iostream>
#include <vector>
#include <set>
using namespace std;
typedef double ldouble;
typedef long long llong;
typedef unsigned int uint;
const int maxN = 100001;
vector<uint> sumup[1001];
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;
for (int i = 0; i < m; ++i)
if (IsSet(mask, i))
curSum += b[i];
if (curSum <= 1000)
sumup[curSum].push_back(mask);
}
vector<uint> possLeft;
/* for (uint mask = 0; mask < (1 << m); ++mask)
possLeft.push_back(mask); */
possLeft.push_back((1 << m) - 1);
vector<uint> temp;
for (int i = 0; i < n; ++i)
{
temp.clear();
// cerr << possLeft.size() << endl;
for (uint left: possLeft)
{
for (uint mask: sumup[a[i]])
{
// cerr << "get " << a[i] << " with " << mask << endl;
if ((mask & left) == mask)
temp.push_back(left ^ mask);
}
}
possLeft.swap(temp);
}
// 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... |