제출 #1297409

#제출 시각아이디문제언어결과실행 시간메모리
1297409baotoan655은행 (IZhO14_bank)C++20
19 / 100
583 ms4452 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 tp = -1; for(int j = 0; j < n; ++j) if(s[j] == sum) tp = j; if(tp == 0) cnt[i] = 1; else if(tp == -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)] == tp) cnt[i] = tp + 1; if(cnt[i] == n) return cout << "YES\n", 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...