Submission #813284

#TimeUsernameProblemLanguageResultExecution timeMemory
813284exodus_Bank (IZhO14_bank)C++14
71 / 100
1088 ms9300 KiB
#include<bits/stdc++.h> using namespace std; int N,M; vector<int>sum[40004]; vector<vector<bool>>memo(30, vector<bool>(2097152, false)); int pip[30]; bool can = false; void dp(int idx, int mask) { if(idx > N-1) { can = true; return; } for(auto x:sum[pip[idx]]) { int ss = mask&x; if(memo[idx][ss]==true) { int lnj = mask|x; dp(idx+1, lnj); } int ses = mask&x; if(ses == 0) { memo[idx][ses]=true; int lanj = mask|x; dp(idx+1, lanj); } } } int main() { cin >> N >> M; vector<int>vek(M); for(int i=0; i<N; i++) { cin >> pip[i]; } for(int i=0; i<M; i++) { cin >> vek[i]; } for(int i=0; i<N; i++) { for(int mask=0; mask<(1<<M); mask++) { int sm=0; for(int k=0; k<M; k++) { int tmp = (mask>>k)&1; if(tmp) sm+=vek[k]; } if(sm==pip[i]) sum[pip[i]].emplace_back(mask); } } dp(0,0); if(can) cout << "YES"; else cout << "NO"; 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...