Submission #607083

#TimeUsernameProblemLanguageResultExecution timeMemory
607083lamBank (IZhO14_bank)C++14
100 / 100
115 ms16732 KiB
#include <iostream> #include <cmath> #include <vector> #include <map> #include <set> #include <algorithm> #define int long long #define ff first #define ss second #define taskname "" #define maxn 20 using namespace std; int dp[(1<<20)],d[1<<20]; int a[20],b[20]; int n,m; bool checkbit(int i, int j) { return i>>j&1; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // freopen(taskname".in","r",stdin); // freopen(taskname".out","w",stdout); cin>>n>>m; for (int i=0; i<n; i++) cin>>a[i]; for (int j=0; j<m; j++) cin>>b[j]; for (int i=0; i<(1<<m); i++) dp[i]=d[i]=-1; dp[0]=d[0]=0; for (int i=1; i<(1<<m); i++) { for (int j=0; j<m; j++) { if (!checkbit(i,j)) continue; int i2=i^(1<<j); if (d[i2]==-1) continue; int val=b[j]+d[i2]; int x=a[dp[i2]]; if (val<x) { dp[i]=dp[i2]; d[i]=val; } else if (val==x) { dp[i]=dp[i2]+1; d[i]=0; } } if (dp[i]==n) { cout<<"YES"; return 0; } } cout<<"NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...