Submission #1299287

#TimeUsernameProblemLanguageResultExecution timeMemory
1299287baotoan655Bank (IZhO14_bank)C++20
100 / 100
146 ms4536 KiB
#include <bits/stdc++.h> #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } using namespace std; const int N = 20; const int M = 1 << N; int a[N], b[N]; int s[N]; int cnt[M]; int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; for(int i = 0; i < n; ++i) { cin >> a[i]; s[i] += a[i]; s[i + 1] += s[i]; } for(int i = 0; i < m; ++i) cin >> b[i]; for(int i = 0; i < (1 << m); ++i) { int x = i; int sum = 0; for(int j = 0; j < m; ++j) if(x >> j & 1) sum += b[j]; int type = -1; for(int j = 0; j < n; j++) if(s[j] == sum) type = j; if(type == 0) cnt[i] = 1; else if(type == -1) { for(int j = 0; j < m; j++) if((x >> j) & 1) cnt[i] = max(cnt[i], cnt[i - (1 << j)]); } else { for(int j = 0; j < m; j++) if(((x >> j) & 1) && cnt[i - (1 << j)] == type) cnt[i] = type + 1; } if(cnt[i] == n) { cout << "YES\n"; return 0; } } cout << "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...