제출 #541209

#제출 시각아이디문제언어결과실행 시간메모리
541209status_coding은행 (IZhO14_bank)C++14
100 / 100
559 ms29720 KiB
#include <bits/stdc++.h> //#pragma GCC optimize ("unroll-loops") using namespace std; long long n,m; long long a[22], b[22]; long long sum[2000005]; vector<int> fr[1005]; bool dp[21][2000005]; int sumP[22]; int main() { 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++) sumP[i]=sumP[i-1]+a[i]; for(int mask=0; mask < (1<<m); mask++) { for(int k=0;k<m;k++) if((mask >> k) & 1) sum[mask] += b[k+1]; if(sum[mask] <= 1000) fr[ sum[mask] ].push_back(mask); } if(n == 1) { for(int mask=0;mask < (1<<m); mask++) if(sum[mask] == a[1]) { cout<<"YES"; return 0; } cout<<"NO"; return 0; } for(int mask=0;mask<(1<<m);mask++) dp[0][mask] = true; for(int i=1;i<=n;i++) for(int mask=0; mask < (1<<m); mask++) { if(sum[mask] != sumP[i]) continue; for(int nmask : fr[a[i]]) if((mask | nmask) == mask && dp[i-1][mask - nmask]) dp[i][mask] = true; } bool ok=false; for(int mask=0;mask<(1<<m);mask++) if(dp[n][mask]) ok=true; if(ok) cout<<"YES"; else cout<<"NO"; 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...