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>
using namespace std;
#define ll long long
#define endl '\n'
typedef pair<ll,ll> ii;
const ll inf=1e15;
const ll mod=1e9+7;
const ll maxn=50005;
ll arr[maxn];
ll dp[21][(1<<20)+5];
vector<ll> ks[20005];
bool solve(ll pos, ll bitmask){
if (pos==-1) return true;
if (dp[pos][bitmask]!=-1) return dp[pos][bitmask];
dp[pos][bitmask]=0;
for (auto u:ks[arr[pos]]){
if (!(bitmask&u)){
if (solve(pos-1,bitmask+u))
dp[pos][bitmask]=1;
}
}
return dp[pos][bitmask];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ks[0].emplace_back(0);
memset(dp,-1,sizeof(dp));
ll n,m,ele;
cin>>n>>m;
for (int i=0;i<n;i++){
cin>>arr[i];
}
for (int j=0;j<m;j++){
cin>>ele;
for (int k=20004-ele;k>=ele;k--){
for (auto u:ks[k-ele]){
ks[k].emplace_back(u+(1<<j));
}
}
}
cout<<(solve(n,0)?"YES":"NO");
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... |