Submission #171994

#TimeUsernameProblemLanguageResultExecution timeMemory
171994emil_physmathBank (IZhO14_bank)C++17
71 / 100
1070 ms17472 KiB
#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);
    }
    set<uint> possLeft;
    /* for (uint mask = 0; mask < (1 << m); ++mask)
        possLeft.insert(mask); */
    possLeft.insert((1 << m) - 1);
    for (int i = 0; i < n; ++i)
    {
        // cerr << possLeft.size() << endl;
        set<uint> temp;
        for (uint left: possLeft)
        {
            for (uint mask: sumup[a[i]])
            {
                // cerr << "get " << a[i] << " with " << mask << endl;
                if ((mask & left) == mask)
                    temp.insert(left ^ mask);
            }
        }
        possLeft.swap(temp);
    }
    // cerr << possLeft.size() << endl;
    cout << (possLeft.size() ? "YES" : "NO");
}

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:30:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (uint mask = 0; mask < (1 << m); ++mask)
                         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...