Submission #1001379

#TimeUsernameProblemLanguageResultExecution timeMemory
1001379anHiepBank (IZhO14_bank)C++17
52 / 100
1099 ms10692 KiB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "D:\debug.h"
#else
#define cebug(...) "Orz_chUoNgnn"
#endif

using namespace std;

#define fi first 
#define se second
#define pb push_back
#define ll long long
#define ii pair<int, int>
#define vi vector<int> 
#define vll vector<ll>
#define vii vector<ii>
#define cd complex<double>
const ll mod = 1e9 + 7;
const ll INF = 1e18L + 5;
const double PI = acos(-1);
const int block = 320;
const int N = 20;
int tc, tt = 1;

int n, m;
int a[N + 5], b[N + 5];
vi f[N + 5];
bool dp[N + 5][(1<<N) + 5];
void solve() {
	cin>>n>>m;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=m; i++) cin>>b[i];
	for(int i=1; i<=n; i++) {
		for(int j=0; j<(1<<m); j++) {
			ll sum = 0;
			for(int k=0; k<m; k++)
				if(1 & (j>>k)) sum += b[k + 1];
			if(sum == a[i]) f[i].pb(j);
		}
	}
	dp[0][0] = true;
	for(int i=1; i<=n; i++) {
		for(int j=0; j<(1<<m); j++) {
			for(auto x: f[i])
				if((j & x) == x)
			 		dp[i][j] |= dp[i - 1][j xor x];
		}
	}
	bool ck = false;
	for(int i=0; i<(1<<m); i++)
		ck |= dp[n][i];
	cout<<(ck ? "YES" : "NO");
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen(".INP", "r", stdin);
    // freopen(".OUT", "w", stdout);
    for(int tc=1; tc<=tt; tc++) solve();
    cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n";
    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...