제출 #640445

#제출 시각아이디문제언어결과실행 시간메모리
640445gnhmhp은행 (IZhO14_bank)C++17
71 / 100
1091 ms104968 KiB
#define taskname "bank." #include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); using namespace std; int n, m; int a[20], b[20], sum[20], s[1<<20]; bool c1[1<<20], c2[1<<20]; vector<int> v[1<<20]; void upd(int i) { if (c1[i]) return; c1[i]=true; for (auto x : v[i]) upd(i|(1<<x)); } int main() { fastio; cin >> n >> m; for (int i=0; i<n; ++i) { cin >> a[i]; if (i>0) sum[i]=sum[i-1]; sum[i]+=a[i]; } for (int j=0; j<m; ++j) cin >> b[j]; for (int i=0; i<(1<<m); ++i) for (int j=0; j<m; ++j) if (i & (1<<j)) s[i]+=b[j]; else v[i].push_back(j); upd(0); swap(c1, c2); for (int i=0; i<n; ++i) { fill(c1, c1+(1<<m), 0); for (int j=0; j<(1<<m); ++j) { int x=0; if (i>0) x=sum[i-1]; if (c2[j] && s[j]-x==a[i]) upd(j); } swap(c1, c2); } for (int j=0; j<(1<<m); ++j) { if (c2[j]) { cout << "YES\n"; return 0; } } cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...