제출 #979787

#제출 시각아이디문제언어결과실행 시간메모리
979787batsukh2006은행 (IZhO14_bank)C++17
100 / 100
97 ms16984 KiB
#include<iostream> #include<stdio.h> #include<math.h> #include<map> #include<string> #include<algorithm> #include<vector> #include<string.h> #include<utility> #include<set> #include<cmath> #include<queue> #include<deque> #include<functional> #include<stack> #include<limits.h> #include<iomanip> #include<unordered_map> #include<numeric> #include<tuple> using namespace std; #define MOD 1000000007 #define int long long #define ff first #define ss second #define endl '\n' void solve(){ int n,m; cin>>n>>m; vector<int> a(n),b(m); for(int i=0; i<n; i++) cin>>a[i]; for(int i=0; i<m; i++) cin>>b[i]; vector<pair<int,int> > dp(1<<m); bool ok=0; for(int i=0; i<(1<<m); i++){ for(int k=0; k<m; k++){ if(i&(1<<k)){ if(dp[i^(1<<k)].ss+b[k]==a[dp[i^(1<<k)].ff]){ dp[i]=max(dp[i],{dp[i^(1<<k)].ff+1,0}); }else{ dp[i]=max(dp[i],{dp[i^(1<<k)].ff,dp[i^(1<<k)].ss+b[k]}); } } } if(dp[i].ff==n) ok=1; } if(ok) cout<<"YES"; else cout<<"NO"; } signed main(){ // freopen("248.in", "r", stdin); // freopen("248.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); cout<<endl; } 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...