제출 #1232027

#제출 시각아이디문제언어결과실행 시간메모리
1232027rana_azkaBank (IZhO14_bank)C++20
71 / 100
1095 ms24412 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e18; const int MOD = 1e9+7; const int MAXN = 20; int n, m, k; int a[MAXN+5]; int b[MAXN+5]; int prefix[MAXN+5]; int dp[MAXN+5][2000000]; vector<int> v[MAXN+5]; void mulaidarinol(){} void solve(){ 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++) prefix[i] = prefix[i-1] + a[i]; for(int j = 0; j <= (1 << m); j++) dp[0][j] = 1; for(int i = 1; i <= n; i++){ for(int j = 0; j <= (1 << m); j++){ int temp = 0; for(int k = 0; k < m; k++){ if((j >> k) & 1){ temp += b[m-k]; } } // cerr << j << " : " << temp << ' ' << prefix[i] << endl; if(temp == prefix[i]){ if(i == 1){ dp[i][j] = 1; v[i].push_back(j); } for(auto l : v[i-1]){ if((l | j) == j){ dp[i][j] = 1; v[i].push_back(j); // cerr << i << " : " << l << ' ' << j << endl; } } } } } bool ans = 0; for(int j = 0; j <= (1 << m); j++) ans |= dp[n][j]; if(ans) cout << "YES" << endl; else cout << "NO" << endl; // for(int i = 0; i <= n; i++){ // for(int j = 0; j <= (1 << m); j++){ // cerr << j << " : " << dp[i][j] << endl; // } // cerr << endl; // } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; while(tc--){ // mulaidarinol(); solve(); cerr << endl; } return 0; } /* 1 5 8 4 2 5 1 3 2 6 9 10 5 4 8 6 3 11 2 8 9 10 5 4 8 6 3 11 2 5 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...