Submission #640439

#TimeUsernameProblemLanguageResultExecution timeMemory
640439gnhmhpBank (IZhO14_bank)C++14
71 / 100
1064 ms124504 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 c[1<<20][21]; vector<int> v[1<<20]; void upd(int i, int j) { if (c[i][j]) return; c[i][j]=true; for (auto x : v[i]) upd((i|(1<<x)), j); } 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,0); for (int i=0; i<n; ++i) { for (int j=0; j<(1<<m); ++j) { int x=0; if (i>0) x=sum[i-1]; if (c[j][i] && s[j]-x==a[i]) upd(j, i+1); else c[j][i]=false; } } for (int j=0; j<(1<<m); ++j) { if (c[j][n]) { 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...