제출 #1308740

#제출 시각아이디문제언어결과실행 시간메모리
1308740tredsused70은행 (IZhO14_bank)C++20
100 / 100
88 ms8644 KiB
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mpr make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int nmax = 20, mod = 1000000007, inf = 2000010000, key = 200003, lg = 20, block = 300;
const ll infll = 4000000000000000000;
const ld eps = 1e-9;

int targets[nmax], banknotes[nmax];
int dp[1 << nmax];
int sum[1 << nmax];

void solve()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> targets[i];
    targets[n] = -1;
    for(int i = 0; i < m; i++)
        cin >> banknotes[i];
    for(int i = 1; i < (1 << m); i++) {
        for(int j = 0; j < m; j++) {
            if((i >> j) & 1 && dp[i ^ (1 << j)] >= dp[i]) {
                dp[i] = dp[i ^ (1 << j)];
                sum[i] = sum[i ^ (1 << j)] + banknotes[j];
                if(sum[i] == targets[dp[i]]) {
                    dp[i]++;
                    sum[i] = 0;
                }
            }
        }
        if(dp[i] == n) {
            cout << "YES\n";
            return ;
        }
    }
    cout << "NO\n";
    return ;
}

int main()
{
    //freopen("movie.in","r",stdin);
    //freopen("movie.out","w",stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);
    srand(8713);
    //init();
    int t = 1;
    //cin >> t;
    //int t_ = t;
    //t = rdi();
    while(t--) {
        //cout << "Case #" << t_ - t << ": ";
        solve();
    }
    //flush();
    return 0;
}

/*
20 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...