Submission #881661

# Submission time Handle Problem Language Result Execution time Memory
881661 2023-12-01T17:25:18 Z yifei04 Bank (IZhO14_bank) C++17
0 / 100
1000 ms 2396 KB
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <bitset>


using namespace std;

#define ll long long
#define all(x) x.begin(), x.end()

constexpr int MAXN = 1 << 21;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);

    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    vector<int> b(m);
    for (int &x : b) {
        cin >> x;
    }

    // suppongo di aggiustare una persona alla volta
    int mx = 1 << m;
    vector<bitset<MAXN>> dp(n + 1);

    dp[0][0] = true;

    vector<vector<int>> good_mask(n + 1);
    // per ogni persona vedo che mask va bene
    for (int i = 1; i <= n; ++i) {
        // itero su tutte le submask
        for (int mask = 0; mask < mx; ++mask) { 
            int sum = 0;
            for (int j = 0; j < mx; ++j) {
                if (mask & (1 << j)) {
                    sum += b[i];
                }   
            }

            if (sum == a[i]) {
                good_mask[i].push_back(mask);
            }
        }   
    }

    for (int i = 0; i < n; ++i) {
        for (int mask = 0; mask < mx; ++mask) {
            if (!dp[i][mask]) {
                continue;
            }
            int cur = __builtin_popcount(mask);
            for (int new_mask : good_mask[i + 1]) {
                int cur_add = __builtin_popcount(new_mask);
                int msk = mask | new_mask;
                if (__builtin_popcount(msk) == cur + cur_add) { // e' un set indipendente
                    dp[i + 1][msk] = true;
                }
            }
        }
    }

    for (int mask = 0; mask < mx; ++mask) {
        if (dp[n][mask]) {
            cout << "YES";
            return;
        }
    }

    cout << "NO";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int tt = 1; // cin >> tt;

    while (tt--) {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1026 ms 2396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -