This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e5 + 10;
const ll mod = 998244353;
ll um(ll a, ll b){
return ((1LL * a * b) % mod + mod) % mod;
}
ll subr(ll a, ll b){
return ((1LL * a - b) % mod + mod) % mod;
}
int a[N], b[N], n, m;
bool dp[N], base[N], nw[N];
void calc(int goal, int cur, int sum, int hs){
if(sum == goal){
dp[hs] = true;
return;
}
if(cur == m) return;
if(sum + b[cur] <= goal){
calc(goal, cur + 1, sum + b[cur], hs + (1 << cur));
}
calc(goal, cur + 1, sum, hs);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
//freopen("bank.in", "r", stdin);
//freopen("bank.out", "w", stdout);
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < m; i++){
cin >> b[i];
}
base[0] = 1;
for(int i = 0; i < n; i++){
calc(a[i], 0, 0, 0);
// for(int j = 0; j < (1 << m); j++){
// if(dp[j]) cout << j << " ";
// }
// cout << endl;
for(int j = 0; j < (1 << m); j++){
for(int mask = 0; mask < (1 << m); mask++){
if(!dp[j] || !base[mask]) continue;
if((mask ^ j) == (mask | j)){
// cout << j << " "<< mask << endl;
nw[j | mask] = true;
}
}
}
for(int j = 0; j < (1 << m); j++){
base[j] = nw[j];
nw[j] = false;
dp[j] = false;
}
}
bool can = false;
for(int i = 0; i < (1 << m); i++){
if(base[i]) can = true;
}
if(can) 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... |