제출 #413899

#제출 시각아이디문제언어결과실행 시간메모리
413899bigDuck은행 (IZhO14_bank)C++14
0 / 100
1079 ms7076 KiB
#include<bits/stdc++.h> using namespace std; #define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount //#define int ll int n, m, a[21], b[21]; bool v[20010]; bool vm[21][(1ll<<20)-1 ]; vector<int> msk[21]; vector<pii> g[20010]; int sum[21]; void knapsack_graph(){ v[0]=true; for(int i=1; i<=m; i++){ for(int sum=0; sum<=(20000-b[i]); sum++){ if( (v[sum]==true)){ g[sum].pb({sum+b[i], i}); v[sum+b[i]]=true; } } } return; } void dfs(int s, int ac, int pt){ if(s==sum[pt]){ if(vm[pt][ac]!=true){ vm[pt][ac]=true; msk[pt].pb(ac); } return; } for(auto pr:g[s]){ int u=pr.ft, tp=pr.sc; if( ((ac&(1ll<<(tp-1) ))==0) && (u<=sum[pt]) ){ dfs(u, (ac|(1ll<<(tp-1) )), pt); } } return; } void search_graph(){ msk[0].pb(0); for(int i=0; i<n; i++){ for(int ac:msk[i]){ dfs(sum[i], ac, i+1); } } return; } int32_t main(){ INIT cin>>n>>m; for(int i=1; i<=n; i++){ cin>>a[i]; sum[i]=sum[i-1]; sum[i]+=a[i]; } for(int i=1; i<=m; i++){ cin>>b[i]; } knapsack_graph(); search_graph(); /* for(int ac:msk[n]){ cout<<ac<<"\n"; } */ if(msk[n].size()>0){ cout<<"YES\n"; } else{ cout<<"NO\n"; } 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...