Submission #173087

# Submission time Handle Problem Language Result Execution time Memory
173087 2020-01-03T10:34:14 Z emil_physmath Bank (IZhO14_bank) C++17
0 / 100
3 ms 504 KB
#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

bank.cpp: In function 'int main()':
bank.cpp:33:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (uint mask = 0; mask < (1 << m); ++mask)
                         ~~~~~^~~~~~~~~~
bank.cpp:51:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (uint mask = 0; mask < (1 << m); ++mask)
                             ~~~~~^~~~~~~~~~
bank.cpp:55:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if ((1 << bits[left]) < sumup[a[i]].size())
                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
bank.cpp:55:16: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
             if ((1 << bits[left]) < sumup[a[i]].size())
                ^
bank.cpp:65:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (uint mask = 0; mask < (1 << m); ++mask)
                             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -