이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
const int maxn = 25;
const int max_mask = (1 << 20) + 5;
int n, m;
int a[maxn];
int b[maxn];
vector<int> byMasks[maxn * 1000];
bool dp[maxn][max_mask];
bool is_calculated[maxn][max_mask];
bool f(int pos, int mask)
{
    if (pos == n) return true;
    if (is_calculated[pos][mask] == true) return dp[pos][mask];
    is_calculated[pos][mask] = true;
    bool result = false;
    for (auto curr_mask : byMasks[a[pos]])
    {
        if ((mask & curr_mask) != 0) continue;
        result = (result | (f(pos + 1, (mask | curr_mask))));
    }
    return dp[pos][mask] = result;
}
void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main()
{
    fastIO();
    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 mask = 0; mask < (1 << m); ++mask)
    {
        int curr_sum = 0;
        for (int i = 0; i < m; ++i)
        {
            if ((mask & (1 << i)) != 0)
            {
                curr_sum += b[i];
            }
        }
        byMasks[curr_sum].push_back(mask);
    }
    for (int i = 0; i < n; ++i)
    {
        if (byMasks[a[i]].empty())
        {
            cout << "NO\n";
            return 0;
        }
    }
    if (f(0, 0) == true)
    {
        cout << "YES\n";
    }
    else
    {
        cout << "NO\n";
    }
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |