Submission #563264

#TimeUsernameProblemLanguageResultExecution timeMemory
563264tamthegodBank (IZhO14_bank)C++14
52 / 100
1083 ms1132 KiB
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<bitset>
#include<chrono>
#include<random>
#include<ext/rope>
/* ordered_set
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/

#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 20 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, m, a[maxN], b[maxN];
int f[maxN][1 << 20];
int mask[1 << 20];
void ReadInput()
{
    cin >> n >> m;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=m; i++) cin >> b[i];
}
void Solve()
{
    f[0][0] = 1;
    for(int i=1; i<=n; i++)
    {
        vector<int> vc, vc1;
        for(int mask=0; mask<(1<<m); mask++)
        {
            int sum = 0;
            for(int j=1; j<=m; j++)
            {
                if(mask & (1 << (j - 1))) sum += b[j];
            }
            if(sum == a[i]) vc.pb(mask);
        }
        for(int mask=0; mask<(1<<m); mask++)
        {;
            for(int v : vc)
            {
                if((mask & v) != v) continue;
                if(f[i - 1][mask ^ v])
                {
                    f[i][mask] = 1;
                    break;
                }
            }
        }
    }
    for(int i=0; i<(1<<m); i++)
        if(f[n][i])
        {
            cout << "YES";
            return;
        }
    cout << "NO";
}
int32_t main()
{
  //  freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...