Submission #792573

#TimeUsernameProblemLanguageResultExecution timeMemory
792573LeVanThucBank (IZhO14_bank)C++17
100 / 100
109 ms16800 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define p(x,y) pair<ll,ll>(x,y) #define BIT(i,x) ((x>>i)&1) #define MASK(x) (1<<x) #define ld long double #define __builtin_popcount __builtin_popcountll #define pll pair<ll,ll> template<class T1,class T2> bool maximize(T1 &x,const T2 &y) { if(x<y) { x=y; return 1; } return 0; } template<class T1,class T2> bool minimize(T1 &x,const T2 &y) { if(x>y) { x=y; return 1; } return 0; } void online() { std::ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE // freopen("input.inp", "r", stdin); // freopen("output.out","w", stdout); #else #endif } ll n,m; ll a[25],b[25]; pll f[1100000]; int main() { online(); cin>>n>>m; for(int i=0;i<n;i++) { cin>>a[i]; } for(int i=0;i<m;i++) { cin>>b[i]; } for(int i=0;i<(1<<m);i++) { if(f[i].fi==n) { cout<<"YES\n"; return 0; } for(int j=0;j<m;j++) { if(!BIT(j,i)) { auto [x,y]=f[i]; y+=b[j]; if(y==a[x]) { x++; y=0; } maximize(f[(1<<j)|i],p(x,y)); } } } 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...