Submission #1036689

#TimeUsernameProblemLanguageResultExecution timeMemory
1036689handlenameBank (IZhO14_bank)C++17
100 / 100
115 ms8668 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define float long double const int MOD=1e9+7; // const int MOD=998244353; const int sqn=450; const long double eps=1e-6; const int dx[4]={0,0,1,-1}; const int dy[4]={1,-1,0,0}; long long power(long long a,long long b,long long p=MOD){ long long res=1; while (b>0){ if (b%2==1) res=(res*a)%p; b/=2; a=(a*a)%p; } return res; } int n,m,arr[21],brr[21]; pair<int,int> dp[2000001]; // we pay off people in order // mask is subset of notes used // dp is number of people paid off (a prefix), amount of money left void runtc(){ cin>>n>>m; for (int i=0;i<n;i++){ cin>>arr[i]; } for (int i=0;i<m;i++){ cin>>brr[i]; } for (int i=1;i<(1<<m);i++){ for (int j=0;j<m;j++){ if (!(i&(1<<j))) continue; pair<int,int> cur=dp[i^(1<<j)]; int new_amt = cur.second+brr[j]; if (new_amt < arr[cur.first]){ cur.second=new_amt; dp[i]=max(dp[i],cur); } else if (new_amt == arr[cur.first]){ cur.first++; cur.second=0; dp[i]=max(dp[i],cur); } } if (dp[i].first==n){ cout<<"YES"; return; } } cout<<"NO"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("movie.in","r",stdin); // freopen("movie.out","w",stdout); // freopen("input1.in","r",stdin); // freopen("output1.out","w",stdout); //freopen("tower_rush_input.txt","r",stdin); //freopen("hackercup_output.txt","w",stdout); int tcs; // cin>>tcs; tcs=1; for (int i=1;i<=tcs;i++){ // cout<<"Case #"<<i<<": "; runtc(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...