제출 #879156

#제출 시각아이디문제언어결과실행 시간메모리
879156YassirSalama은행 (IZhO14_bank)C++17
100 / 100
273 ms10076 KiB
#include <iostream> #include <vector> #include <algorithm> #include <unordered_map> #include <set> #include <unordered_set> #include <iomanip> #include <cmath> #include <limits> #include <map> #include <utility> #include <cctype> #include <string> #include <cstring> #include <stack> #include <queue> #include<assert.h> #include <functional> #include <iterator> using namespace std; #define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n"; void dbg_out() { cout << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__); #define endl "\n" #define pb push_back #define F first #define S second #define ll long long #define mod 1000000007 #define all(v) v.begin(),v.end() int dp[1<<(20)]; int n,m; vector<int> a,b; void solve(int i,int mask){ if(i>=n){ cout<<"YES"<<endl; exit(0); return; } if(dp[mask]!=-1) return; vector<vector<int>> cmaskes(a[i]+1); cmaskes[0].push_back(0); for(int j=0;j<m;j++){ if(mask&(1<<j)) continue; for(int k=a[i];k>=b[j];k--){ for(auto msk:cmaskes[k-b[j]]){ cmaskes[k].push_back((1<<j)|msk); } } } dp[mask]=1; for(auto x:cmaskes[a[i]]) solve(i+1,(mask|x)); } signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); cin>>n>>m; for(int i=0;i<n;i++) { int x; cin>>x; a.pb(x); } for(int i=0;i<m;i++){ int x; cin>>x; b.pb(x); } memset(dp,-1,sizeof(dp)); solve(0,0); cout<<"NO"<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...