This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* hello
* author: N29
* created: 2024-11-01 09:43:33
**/
#include<bits/stdc++.h>
using namespace std;
#ifndef BADGNU
#pragma GCC target("sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
// #define int ll
#define ld long double
#define y1 cheza
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=1e5+100;
const int M=5001;
const int B=447;
const int mod=998244353;
const ll INF=1e18;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
const double eps=1e-6;
int n,m;
int a[25];
int b[25];
int pref[(1ll<<20ll)];
int mask[(1ll<<20ll)];
int mask2[(1ll<<20ll)];
void print(int x){
for(int y=x;;y=(y-1)&x){
cout<<y<<' ';
if(y==0)break;
}
cout<<'\n';
}
void test(){
cin>>m>>n;
for(int i=1;i<=m;i++){
cin>>b[i];
}
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
sort(b+1,b+m+1);
for(int i=0;i<(1ll<<n);i++){
for(int j=0;j<n;j++){
if((1ll<<j)&(i)){
pref[i]=(pref[i]+a[j+1]);
}
}
}
mask[0]=1;
for(int i=1;i<=m;i++){
bool ok=1;
for(int j=0;j<(1ll<<n);j++){
if(pref[j]==b[i]){
int cur=((1ll<<n)-j-1);
for(int k=cur;;k=((k-1)&cur)){
if(mask[k]){
mask2[k^j]=1;
ok=0;
}
if(k==0)break;
}
}
}
for(int j=0;j<(1ll<<n);j++){
mask[j]=mask2[j];
mask2[j]=0;
}
if(ok){
cout<<"NO\n";
return;
}
}
cout<<"YES\n";
}
/*
*/
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// cout.tie(nullptr);
int t2=1;
// cin>>t2;
for(int i=1;i<=t2;i++){
test();
}
}
# | 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... |