제출 #847587

#제출 시각아이디문제언어결과실행 시간메모리
847587Ahmed_Salah7Bank (IZhO14_bank)C++17
100 / 100
337 ms4132 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 5, M = 1e6 + 6, mod = 998244353;
vector<int> mask[22];
int a[22], b[22];
bool vis[(1 << 20)];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("bank.in","r",stdin);
    //freopen("bank.out","w",stdout);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> b[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < (1 << m); ++j) {
            int sum = 0;
            for (int k = 0; k < m; ++k) {
                sum += b[k] * ((j >> k) & 1);
            }
            if (sum == a[i])
                mask[i].push_back(j);
        }
    }
    vector<int> masks;
    masks.push_back(0);
    for (int i = 0; i < n; ++i) {
        vector<int> _masks;
        for (auto x: mask[i]) {
            for (auto y: masks) {
                if (!(x & y) && !vis[x | y]) {
                    _masks.push_back(x | y);
                    vis[x | y] = 1;
                }
            }
        }
        masks = _masks;
    }
    cout << (masks.empty() ? "NO" : "YES");
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...