Submission #499165

#TimeUsernameProblemLanguageResultExecution timeMemory
499165mewnianBank (IZhO14_bank)C++14
100 / 100
115 ms16764 KiB
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#define sze(x) (ll) x.size()
#define idx(x, a) get<x>(a)
#define LID(x) (x << 1LL)
#define RID(x) (x << 1LL) + 1LL
#define ID(x) (x + MAXN)
#define CONV(x) (x - MAXN)
#define countbit(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pi;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r)
{
    return uniform_int_distribution<ll>(l, r)(rng);
}

const ll MAXN = 23;
const ll MAXBIT = (1LL << 20) + 3;
const ll INF = 1e18;

ll n, m, a[MAXN], b[MAXN], tar[MAXN];
ll dp[MAXBIT], filled[MAXBIT];
bitset<MAXBIT> ok;

inline bool bit_on(ll mask, ll bit)
{
    return ((mask >> bit) & 1LL);
}
inline ll submask(ll mask, ll bit)
{
    return (mask ^ (1LL << bit));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef OFFLINE
    freopen("input.inp", "r", stdin);
    #endif
    cin >> n >> m;
    for (ll i = 0; i < n; ++i) cin >> a[i];
    a[n] = -1;
    for (ll i = 0; i < m; ++i) cin >> b[i];
    ok[0] = 1;
    for (ll i = 0; i < n; ++i) ok[tar[i]] = 1;
    dp[0] = filled[0] = 0;
    for (ll mask = 1; mask < (1LL << m); ++mask)
    {
        dp[mask] = 0;
        for (ll i = 0; i < m; ++i)
        {
//            cerr << bit_on(mask, i);
            if (!bit_on(mask, i)) continue;
            ll maskt = submask(mask, i);
            pi dpt = mp(dp[maskt], filled[maskt] + b[i]);
            if (filled[maskt] + b[i] == a[dp[maskt]])
                ++dpt.fi, dpt.se = 0;
            tie(dp[mask], filled[mask]) = max(mp(dp[mask], filled[mask]), dpt);
        }
//        cerr << " = " << dp[mask] << " " << filled[mask] << endl;
    }
    cout << (dp[(1LL << m) - 1] == n ? "YES" : "NO");
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...