제출 #1308550

#제출 시각아이디문제언어결과실행 시간메모리
1308550Agageldi은행 (IZhO14_bank)C++20
71 / 100
1099 ms156824 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define N 500005 int tc = 1, n, a[N], m, b[N], dp[21][(1<<20)], sm[(1<<20)]; vector <int> E[N]; void solve(int x, int nm, int i, int j) { if((1 << x) >= (1<<m)) { dp[i + 1][nm] |= dp[i][nm ^ j]; return; } solve(x + 1, (nm | (1 << x)), i, j); if(!((j >> x) & 1)) { solve(x + 1, nm, i, j); } } int32_t main() { ios::sync_with_stdio(0);cin.tie(0); cin >> n >> m; for(int i = 0; i < n; i++) { cin >> a[i]; } for(int i = 0; i < m; i++) { cin >> b[i]; } for(int i = 0; i < (1 << m); i++) { dp[0][i] = 1; int sum = 0; for(int j = 0; j < m; j++) { if((i >> j) & 1) sum += b[j]; } E[sum].push_back(i); } for(int i = 0; i < n; i++) { for(auto j : E[a[i]]) { solve(0, 0, i, j); } } bool ok = 0; for(int i = 0; i < (1 << m); i++) { if(dp[n][i]) { ok = 1; break; } } cout <<(ok == 1? "YES\n" : "NO\n"); 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...