제출 #944631

#제출 시각아이디문제언어결과실행 시간메모리
944631beepbeepsheep은행 (IZhO14_bank)C++17
100 / 100
103 ms185936 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' typedef pair<ll,ll> ii; const ll inf=1e15; const ll mod=1e9+7; const ll maxn=50005; ll arr[maxn]; ll dp[21][(1<<20)+5]; vector<ll> ks[20005]; bool solve(ll pos, ll bitmask){ if (pos==-1) return true; if (dp[pos][bitmask]!=-1) return dp[pos][bitmask]; dp[pos][bitmask]=0; for (auto u:ks[arr[pos]]){ if (!(bitmask&u)){ if (solve(pos-1,bitmask+u)) dp[pos][bitmask]=1; } } return dp[pos][bitmask]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); ks[0].emplace_back(0); memset(dp,-1,sizeof(dp)); ll n,m,ele; cin>>n>>m; for (int i=0;i<n;i++){ cin>>arr[i]; } for (int j=0;j<m;j++){ cin>>ele; for (int k=20004-ele;k>=ele;k--){ for (auto u:ks[k-ele]){ ks[k].emplace_back(u+(1<<j)); } } } cout<<(solve(n,0)?"YES":"NO"); 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...