Submission #1280368

#TimeUsernameProblemLanguageResultExecution timeMemory
1280368peanutBank (IZhO14_bank)C++20
52 / 100
1095 ms720 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

vector<int> dx = {0, 0, 1, -1};
vector<int> dy = {1, -1, 0, 0};

const int maxn = 20 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int salary[maxn], notes[maxn];
bool dp[21][1 << 20];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    int n, m; cin >> n >> m;
    for (int i = 0; i < n; ++i) cin >> salary[i];
    for (int i = 0; i < m; ++i) cin >> notes[i];

    vector<vector<int>> valid(n);
    for (int i = 0; i < (1 << m); ++i)
    {
        int sum = 0;
        for (int j = 0; j < m; ++j) if (i >> j & 1) sum += notes[j];
        for (int j = 0; j < n; ++j) if (sum == salary[j]) valid[j].pb(i);
    }
    dp[0][0] = true;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < (1 << m); ++j)
        {
            for (auto k : valid[i-1]) if ((k & j) == k) dp[i][j] |= dp[i-1][j ^ k];
        }
    }

    for (int i = 0; i < (1 << m); ++i)
    {
        if (dp[n][i])
        {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...