제출 #579873

#제출 시각아이디문제언어결과실행 시간메모리
579873karrigan은행 (IZhO14_bank)C++14
19 / 100
74 ms18848 KiB
#include <bits/stdc++.h> using namespace std; vector<long long>c[1009]; long long a[1009]; long long b[1009]; long long dp[21][1<<20]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("bank.in","r",stdin); //freopen("bank.out","w",stdout); int n,m; 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=0;i<(1<<m);i++){ long long temp=0; for (int j=0;j<m;j++){ if (i>>j&1){ temp+=b[j+1]; } } if (temp<=1000){ c[temp].push_back(i); } } dp[0][0]=1; for (int i=1;i<=n;i++){ for (int j=0;j<(1<<m);j++){ if (dp[i-1][j]==1){ long long temp=(1<<m)-1-j; bool flag=false; for (auto v:c[a[i]]){ if ((temp&v)==v){ dp[i][j+v]=1; flag=true; } } if (flag==false){ cout<<"NO"; return 0; } } } } for (int j=0;j<(1<<m);j++){ if (dp[n][j]==1){ cout<<"YES"; return 0; } } 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...