제출 #679283

#제출 시각아이디문제언어결과실행 시간메모리
679283Hacv16은행 (IZhO14_bank)C++17
52 / 100
1090 ms7756 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") const int MAX = 22; const int MAXM = 50005; const int INF = 0x3f3f3f3f; int n, m, a[MAX], b[MAX]; bool dp[MAX][1 << MAX]; vector<int> g[MAXM]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; for(int mask = 0; mask < (1 << m); mask++){ int cur = 0; for(int i = 0; i < m; i++) if(mask & (1 << i)) cur += b[i]; g[cur].emplace_back(mask); } for(int i = 1; i <= n; i++){ if(g[a[i]].empty()){ cout << "NO" << '\n'; return 0; } } dp[0][0] = true; for(int i = 1; i <= n; i++){ for(int mask = 0; mask < (1 << m); mask++){ for(auto sub : g[a[i]]){ if((mask & sub) != sub) continue; dp[i][mask] |= (dp[i - 1][mask ^ sub]); if(dp[i][mask]) break; } } } bool pos = false; for(int mask = 0; mask < (1 << m) && !pos; mask++) pos |= dp[n][mask]; cout << (pos ? "YES" : "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...