Submission #1133228

#TimeUsernameProblemLanguageResultExecution timeMemory
1133228sitingfakeBank (IZhO14_bank)C++20
71 / 100
1097 ms15724 KiB
#include<bits/stdc++.h> using namespace std; #define execute cerr << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s"; #define ll long long #define ii pair<int,int> #define se second #define fi first #define iii pair<int,ii> #define all(v) v.begin(),v.end() #define bit(x,i) ((x>>(i))&1) #define off(x,i) (x^(1<<(i))) #define ms(d,x) memset(d,x,sizeof(d)) #define sitingfake 1 #define orz 1 const int mod=1e9+7; const long long linf=1e18+3; const int inf=1e9; const int maxarr=1e6+5; const double pi=acos(-1); const int dx[]={0,1,-1,0}; const int dy[]={1,0,0,-1}; int n,m; int a[22],b[22]; namespace sub3 { bool dp[1<<20][21]; int val[1<<20]; void init() { for(int mask=1;mask<(1<<m);mask++) { int tmp=0; for(int i=0;i<m;i++) { if(bit(mask,i)) tmp+=b[i+1]; } val[mask]=tmp; } } void solve() { init(); dp[0][0]=1; for(int i=1;i<=n;i++) { for(int mask=1;mask<(1<<m);mask++) { for(int sub=mask;1;sub=(sub-1)&mask) { if(val[sub]==a[i]) { dp[mask][i]|=dp[mask^sub][i-1]; } if(sub==0) break; } } } for(int mask=1;mask<(1<<m);mask++) if(dp[mask][n]) { cout<<"YES"; return; } cout<<"NO"; } } namespace sub1 { void solve() { for(int mask=1;mask<(1<<m);mask++) { int tmp=0; for(int i=0;i<m;i++)if(bit(mask,i)) tmp+=b[i+1]; if(tmp==a[1]) { cout<<"YES"; return; } } cout<<"NO"; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) cin>>b[i]; if(n==1) sub1::solve(); else sub3::solve(); //execute; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...