제출 #333958

#제출 시각아이디문제언어결과실행 시간메모리
333958limabeans은행 (IZhO14_bank)C++17
0 / 100
1093 ms1388 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl using ll = long long; const int maxn = 22; int n, m; int a[maxn]; int b[maxn]; bool dp[maxn][1<<20]; int main() { ios_base::sync_with_stdio(false); 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]; } 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++) { for (int s=mask; ;s=((s-1)&mask)) { int use = mask^s; int sum = 0; for (int j=0; j<m; j++) { if (use>>j&1) sum += b[j]; } if (dp[i-1][s] && sum==a[i]) { dp[i][mask]=true; } if (s==0) break; } } } for (int mask=0; mask<1<<m; mask++) { if (dp[n][mask]) out("YES"); } out("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...