Submission #541392

#TimeUsernameProblemLanguageResultExecution timeMemory
541392status_codingBank (IZhO14_bank)C++14
100 / 100
113 ms8532 KiB
#include <iostream> using namespace std; int n,m; int a[22], b[22]; int dp[2000005], leftVal[2000005]; int main() { cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) cin>>b[i]; for(int mask=1; mask < (1<<m); mask++) { dp[mask] = -1; leftVal[mask] = -1; } for(int mask=0; mask < (1<<m); mask++) { for(int last=0;last<m;last++) { if(((mask>>last)&1) == 0) continue; int prev = mask - (1<<last); if(dp[prev] == -1) continue; int nVal = leftVal[prev] + b[last+1]; int target = a[ dp[prev] + 1 ]; if(nVal < target) { dp[mask] = dp[prev]; leftVal[mask] = nVal; } else if(nVal == target) { dp[mask] = dp[prev] + 1; leftVal[mask] = 0; } if(dp[mask] == n) { cout<<"YES"; return 0; } } } 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...